Disabling UP and DOWN key in ListView

When the user clicks on an item in a ListView table, how can I disable the UP and DOWN keys? I have them doing nothing, but I want the highlighted item not to move until the user clicks on another item. I think you set a flag in WM_KEYUP and WM_KEYDOWN in WndProc to say do nothing, but not sure what to set.
this is confusing. Those are not the up and down keys, those are events, but its almost like you knew that?

you can use those events, either or both for this (or just on key pressed, etc), the wParam field would be VK_UP or VK_DOWN for the two arrow buttons.

doing nothing just requires an empty handler for keyboard events.
if you want it to do something, you need to say if the key pressed was whatever key, then do whatever action.

it sounds like you need some exotic condition is all..
on key pressed
if key is VK_UP and something (some bool after detecting another item clicked?)
do activity
else do nothing
Last edited on
I'm doing this in my WndProc:

case WM_KEYDOWN:
switch(wParam)
{
case VK_UP:
case VK_DOWN:
return(0);
}

This doesn't work, but I think this is the same as not having a WM_KEYDOWN statement. ListView, upon creation, has the 2 arrows UP and DOWN activated by default. Just trying to deactivate them or do nothing when pressed. They currently move up and down the list of items. I don't want that.
In fact, this doesn't even catch the WM_KEYDOWN event, so still working on figuring it out.
I suspect you'll have to subclass ListView and then provide your own wndProc for the new class which ignores the required messages and passes all others to the wndProc for ListView.

https://docs.microsoft.com/en-us/windows/win32/controls/subclassing-overview
It's actually a LVN_KEYDOWN message within a WM_NOTIFY event. Not a WM_KEYDOWN event.
Apparently, the only way to reset all the controls within a ListView back to the default (which is unselectable) is to use EnableWindow(hwnd,FALSE), then EnableWindow(hwnd,TRUE). This allows the scroll bar to be active to scroll thru the list, but not be able to do anything else. If you use ListView_SetExtendedListViewStyle to allow row clicks, there is no way that I have found to revert back to no row clicks allowed (but still allow scrolling) except by disabling the window and reenabling it again. I've tried capturing mouse clicks and key strokes with the window enabled, but nothing has every worked.
Topic archived. No new replies allowed.