jsist
jsist

Reputation: 5253

Win32 c++: How to get number of checked items in treeview control

I have a Treeview control with each item having a checkbox. At root level i have around 100 items and each such item has 100 further items, so traversing the tree takes time of about 1-2 seconds. I want to reduce that time. So here is my question, How to get number of checked items in the treeview control without traversing through the treeview control?

I checked msdn. There we have "Treeview_GetCount" but it gives total number of items in treeview control. I know i can start from root and traverse down recursively to check state of each item in tree view and finally get the number of items with checked state.

Alternative we may have a variable (class member or global) and increment it when item is checked and decrement it when item is unchecked, that will finally give me number of items in one instance.

Is there any other better way then these?

Upvotes: 1

Views: 1370

Answers (2)

bowman han
bowman han

Reputation: 1135

There isn't any notification. You can write your own, though. Just handle mouse click and use hittest to see if the mouse cursor is on the state image. For completeness handle the space key and send the same notification for the selected item too.

Upvotes: 0

Mike Kwan
Mike Kwan

Reputation: 24447

Unfortunately, you have to traverse the tree view calling TreeView_GetCheckState to get such information. Alternatively, you can associate check state through the lParam of TVITEM when inserting items but this still requires traversal.

What is the problem with traversing the control? If it is too slow for some reason, you can always store the number in a variable which you update.

Upvotes: 1

Related Questions