Reputation: 401
My application is displaying a Hugh amount of files system entries held in memory using a ctreectrl
, adding all the items takes ~20seconds even when using SetRedraw(False)
, so how to make a completely virtual(breadth,depth) ctreectrl
& how to populate it ?
Edit#1 I want to display the displayed portion items expanded from the beginning , but I don't want to store them in the tree, for example
Root-->
Child1-->
SubChile1
Child2
Child3
Upvotes: 3
Views: 1344
Reputation: 33804
you must not add all items at once. you must add only top level items with cChildren = I_CHILDRENCALLBACK
and handle WM_NOTIFY
code == TVN_GETDISPINFO
if mask & TVIF_CHILDREN
set
cChildren
(TRUE or FALSE)code == TVN_ITEMEXPANDING
, action == TVE_EXPAND
- expand
node - add only direct child items (one level) again with
cChildren = I_CHILDRENCALLBACK
and possible
code == TVN_ITEMEXPANDED
, action == TVE_COLLAPSE
- collapse
node - remove all childssense of cChildren = I_CHILDRENCALLBACK
- if you add folder to list, you not need at once initialize it (open handle, enum childs) - only when you first time got I_CHILDRENCALLBACK
(this when your item become visible, but if containing folder large enough(like system32) - it have too many items, but visible only several top at begin, new begin visible when user scroll down)- open folder, determinate are it have subitems (and based on this set cChildren
) but not full enumerate it (do this only on <TVN_ITEMEXPANDING, TVE_EXPAND>
Upvotes: 3
Reputation: 15375
I have no advice to make it virtual. I use for large tree structures the possibility of collecting a child branch only when it is need. I trap TVN_ITEMEXPANDING
So how to do it: First read the first level (root), than keep all root node collapsed and read all child nodes of the root (just 1 level deep) and populate them.
When a node expands, you already have the nodes, now read the next level below the childs of the expanding node.
So you see only the expanded nodes plus one invisible level.
I do this in this way to show all nodes that are expandable with the + sign. All nodes without children nodes are shown without it as leafs.
The second way is not to fill the string data and let the tree load it via callback. But the impact is small. The real problem with the speed are the number of nodes.
Upvotes: 2