Easy to reproduce problem using default MFC dialog application:
- Add listview control and link it to
CListCtrl
class -m_listCtrl
. - Enable "owner data" or
LVS_OWNERDATA
flag to enable virtual list view mode. Enable multiple selection and "Always show selection". - In
OnInitDialog()
add at least one column and callm_listCtrl.SetItemCount()
to set number of items in the list to more than one. - Link button click with a method that calls
m_listCtrl.SetItemState(-1, 0, LVIS_SELECTED);
That call should deselect all entries in the list. - Click on item in the list and use SHIFT + arrow key to extend selection to at least two entries. If selection is extended with mouse or CTRL + click or CTRL + SHIFT, then the issue doesn't appear.
- Click on a button that triggers
SetItemState()
call in step (4) and notice that items don't get deselected the first time. They only get deselected the second time.
Is that a bug in listview control or am I doing something wrong?
Calling m_listCtrl.SetItemState(-1, 0, LVIS_SELECTED);
should deselect all entries with the first call, but it does so only when called twice.