Igor Jerovsek
Igor Jerovsek

Reputation: 1

MFC: CListView: Why SetItemState(-1, 0, LVIS_SELECTED) doesn't work if multiple items were selected with SHIFT + arrow key?

Easy to reproduce problem using default MFC dialog application:

  1. Add listview control and link it to CListCtrl class - m_listCtrl.
  2. Enable "owner data" or LVS_OWNERDATA flag to enable virtual list view mode. Enable multiple selection and "Always show selection".
  3. In OnInitDialog() add at least one column and call m_listCtrl.SetItemCount() to set number of items in the list to more than one.
  4. Link button click with a method that calls m_listCtrl.SetItemState(-1, 0, LVIS_SELECTED); That call should deselect all entries in the list.
  5. 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.
  6. 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.

Upvotes: 0

Views: 333

Answers (0)

Related Questions