Solved

ListView checkboxes and spacebar

Posted on 2007-03-18
3
592 Views
Last Modified: 2008-02-01
I have listview with checkboxes. When the listview is selected, and user presses the Spacebar key, the selected item gets checked / unchecked. Listview does this.

But when user presses Alt + Spacebar, the item also gets checked / unchecked, AND the application menu is displayed too. I do not want the item to get checked if user presses alt  + spacebar. How do I do that? Checkboxes, for example, work fine, but listview has this bug. I use the version 6 of common controls.

Also please note that pressing Alt, releasing it, and pressing spacebar after that also opens the application menu normally. This behavior should be preserved. But anything is better than nothing, so all answers are appreciated.
0
Comment
Question by:JiriNovotny
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 22

Accepted Solution

by:
danaseaman earned 500 total points
ID: 18743459
Looked at some code and found:
VbSpace w/o Alt toggles check status via WM_KEYDOWN.
You can disable the checking by using ISubClass_WindowProc = 1 in lieu of ISubClass_WindowProc = CallOldWindowProc(hwnd, msg, wParam, lParam), however this does not disable the Alt+VbSpace which appears to be handled internal to ComCtl32.Dll.

You need to subclass the control and monitor message LVN_ITEMCHANGING and when there is a state change AND ShiftState = vbAltMask then just cancel the change. This is actual code for modified VbAccelerator ListView that fixes this problem.

            Case LVN_ITEMCHANGING
               
               ISubClass_WindowProc = CallOldWindowProc(hwnd, msg, wParam, lParam)
               ' Editing the state of an item
               CopyMemory tNMLVOD, ByVal lParam, Len(tNMLVOD)
               bOldState = (tNMLVOD.uOldState And LVIS_STATEIMAGEMASK) = &H2000
               bNewState = (tNMLVOD.uNewState And LVIS_STATEIMAGEMASK) = &H2000
               If bOldState <> bNewState Then
                  iShift = pShiftState()
                  Debug.Print "bOldState <> bNewState", iShift
                  If iShift = vbAltMask Then
                     ISubClass_WindowProc = 1 'Cancel the change
                     Debug.Print "Disable Alt+Space"
                     Exit Function
                  End If
               End If

If you wish to do this to the Vb ListView just add a suitable subclass component and take over control of LVN_ITEMCHANGING as shown above.
0
 

Author Comment

by:JiriNovotny
ID: 18750349
Thanks for your great answer.

I want to do this for standard VB6 ListView. For some reason, subclassing doesn't work:

AttachMessage Me, lvTasks.hWnd , LVN_ITEMCHANGING

I do not receive any messages. I use SSubtimer6 from VbAccelerator
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question