Enable/Disable ListView rows

I have an OverView window with 2 ListViews. In this OverView window, none of the ListView rows can be selected as it is just a scrollable data window. Each ListView is redisplayed in other windows, when another tab is selected. In these separate windows, I allow the rows to be selectable by the following line and it works great.

ListView_SetExtendedListViewStyle(hwnd_pt_list,LVS_EX_FULLROWSELECT);

When I go back to the OverView window, I want the rows on the 2 ListViews to revert back to not selectable after redisplaying. I tried

ListView_SetExtendedListViewStyle(hwnd_pt_list,0);

but that didn't work. There wasn't a mask option that seemed to apply. How can I turn off row selection?
Last edited on
You can basically unselect items using ListView_SetItemIndexState(...). See:

https://docs.microsoft.com/en-us/windows/win32/api/commctrl/nf-commctrl-listview_setitemindexstate

I doubt that it is possible to enable/disable items. But it's that horribly overcomplicated that I wouldn't completely exclude that...
I tried that. But, unselecting items doesn't prevent the table rows from being selectable in the future. I need them to be unable to be selected on one screen, but able to be selected on another screen. I have only found a way to make the table rows selectable, but once they become selectable, it stays that way. When the ListView is created, by default the rows are not selectable. Since there is a way (stated in my OP) to make the rows selectable, there should be a way to make them not selectable again.

The only way I got it to work, was to hide the table, delete the table object completely, and then recreate it so it goes back to the default condition that is not selectable. Terribly inefficient.

Maybe there is another way more efficient, but I haven't discovered it yet.
Actually LVS_EX_FULLROWSELECT is only the style how to select. Not whether or not to select.

For not making the item selectable I found only this way:

https://docs.microsoft.com/en-us/windows/win32/controls/wm-notify
https://docs.microsoft.com/en-us/windows/win32/controls/lvn-itemchanging

Within this message you can tell the system that this items cannot change after you set those items to unselected (using the ListView_SetItemState(...) function).
I see what you are saying. However, when the ListView is created using flags WS_VISIBLE|WS_CHILD|WS_BORDER|LVS_REPORT and populated with items and subitems, there is some initial mechanism where the rows are not yet selectable at all. Apparently, there is no way to know why that is. That is a behind the scenes question, I guess. And, LVS_EX_FULLROWSELECT allows the ability to select a row. There is no WM_NOTIFY in my existing code, so there is another mechanism that allows the ListView to be not selectable after creation using the flags above.

It just seems to me that your WM_NOTIFY method or my recreate method is a lot of unnecessary work (but necessary to get this to work) to simply turn back off any type of selection method.
You can however enable/disable the whole window:

https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-enablewindow

there is some initial mechanism where the rows are not yet selectable at all.
It is possible that the control does not have the focus. You can change it using SetFocus(...). See:

https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setfocus
I'll try some of those variations for fun and see what happens. Thanks.
The SetFocus didn't fix it, but the EnableWindow function is perfect. Does exactly what I was looking for.
Registered users can post here. Sign in or register to post.