Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
By default list control does not support deselecting an existing selection if we click on the same item. What I needed is to deselect an item if select an existing selected item.
I have implemented a virtual list and owner draw is enabled to draw custom row.
And handled the NM_CLICK event to deselect an already selected item.
What I am seeing on clicking an already selected item it getting deselected first. But suddenly the DrawItem() is invoked for all the items where the below condition is true for all items.
if ((lpDrawItemStruct->itemState & ODS_SELECTED) == ODS_SELECTED)

Please find the sample code at https://github.com/ajayclouds/Sample/tree/main/virtuallist_demo[^]. I will appreciate your help.

I used the sample code from Using virtual lists[^] and update the below things:
Enabled the Owner Draw Fixed property of the list control. Then derived a class from CListCtrl and override DrawItem().

What I have tried:

I tried option like save the selections at the start of
OnCLickItem 
and restored the state of all rows at the end of the
OnCLickItem 
. But the problem not solved. Something is triggering DrawIitem with wrong item state.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900