m_drinks_coffee
m_drinks_coffee

Reputation: 507

C++ MFC - CTreeCtrl - Difference between SelectItem and SetItemState

I need to create a Tree List for my windows application, with multiple selection of nodes with drag-and-drop support. Since Microsoft doesn't provide any such property for the tree which eases the work of the developer, I have to implement this features on my own.

Can somebody explain me the differences (also, the corresponding getters for the following statements) and when to use

SetItemState(hItem, 1, TVIS_SELECTED);

and

SelectItem(hItem);

and

SetItemState(hItem, TVIS_SELECTED, TVIS_SELECTED);

Upvotes: 2

Views: 2471

Answers (1)

Michael Urman
Michael Urman

Reputation: 15905

The primary difference is that SelectItem is functionally built off of SetItemState. Along with anything else it does, SelectItem will use SetItemState (or equivalent internal calls) to set TVIS_SELECTED for the new item, and, say, remove it from the previously selected item.

In order to implement your own multiple-selection control, you have to prevent SelectItem from being called when you want to augment the selection instead of replacing it. There are a lot of cases to consider, ranging from mouse clicks with various modifier keys held to keyboard navigation, so good luck in your implementation!

Upvotes: 2

Related Questions