Solved

ListView checkboxes and spacebar

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now