1
votes

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?

2
Those are your options. The TreeView control is not a SQL server.Raymond Chen
TreeView: It's dumber than you think it is.i_am_jorf

2 Answers

1
votes

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.

0
votes

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.