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?
Unfortunately, you have to traverse the tree view calling TreeView_GetCheckState to get such information. Alternatively, you can associate check state through the
lParamofTVITEMwhen 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.