Solved

ListView checkboxes and spacebar

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

820 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