Solved

ListView checkboxes and spacebar

Posted on 2007-03-18
3
588 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
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

821 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