Solved

ListView checkboxes and spacebar

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

920 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