3

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
M.U
  • 381
  • 3
  • 10
  • *treeview* can not be virtual like *listview* because it not plain, but have complex structure. so message like `LVM_SETITEMCOUNT` is not enough for tree. you need direct add every item. `I don't want to store them in the tree` - so it and will be not in tree and will be not shown anyway - you have no choice. but you can "smart" add items - not all at once but visible only. and expand it by request. and not store say name in item but use `I_*CALLBACK` and handle `TVN_GETDISPINFO` – RbMm May 11 '17 at 08:31

2 Answers2

3

you must not add all items at once. you must add only top level items with cChildren = I_CHILDRENCALLBACK and handle WM_NOTIFY

  • with code == TVN_GETDISPINFO if mask & TVIF_CHILDREN set cChildren (TRUE or FALSE)
  • with code == TVN_ITEMEXPANDING, action == TVE_EXPAND - expand node - add only direct child items (one level) again with cChildren = I_CHILDRENCALLBACK

and possible

  • with code == TVN_ITEMEXPANDED, action == TVE_COLLAPSE - collapse node - remove all childs

sense 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>

RbMm
  • 31,280
  • 3
  • 35
  • 56
2

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.

xMRi
  • 14,982
  • 3
  • 26
  • 59