Hi,
I am using TAdvTreeView in Virtual Mode. Things went very well with displaying simple trees but some deeper understanding about the inner workings of TAdvTreeView in Virtual Mode seems to be necessary in order to achieve more complex tree operations.
Asumption: Virtual Mode is usefull every time you already have some kind of tree data structures in your own classes and want those to be displayed in the TAdvTreeView.
The simple aproach is to implement the events for OnGetNumberOfNodes and OnGetNodeText as a minimum requirement. To do this you need some kind of mapping between the virtual tree nodes and your real data nodes. Depending on your own data structures you could use the Anode.Row as a key to identify your real data object.
But the Row number is subject to be changed when nodes are inserted for example. To map the virtual nodes of the TAdvTreeView I implemented a mapping function that takes a virtual node and returns the real node of my underlying data objects. This function uses an array of the index values oft he path between the virtual root node tot he actual virtual node that I want to map. With this path information, the mapping function walks down the real data tree and returns the found node.
This worked very well for displaying my existing tree structures in a TAdvTreeView Component.
Now I started to add and delete nodes to my real data tree and called TAdvTreeView1.Invalidate. I expected the tree would then call the OnGetNumberOfNodes and OnGetNodeText events to update the affected nodes which are actually visible. But that didn?t work.
Then I figured I may have to use the methods AddVirtualNode(parent) and RemoveVirtualNode. This seemed to work initially in simple trees but there are side effects.
The questions that arise are as follows: What hast to be done first? Adding a new virtual node or adding a node to my real data tree? If I add a new virtual node first, then that triggers OnGetNumberOfNodes/OnGetNodeText events which report wrong values because the node is not yet in the real data tree. If I add the real node to my real data tree first, then the OnGetNumberOfNodes/OnGetNodeText events already report the new values befort the call to AddVirtualNode. In both cases I see weired behaviour in the displayed tree with this symptom: An already expanded node has a + sign infront of it. And if I click that the node, it expands and looks like it has multiple children lists.
Anyway. This leads to general question of how to use a TAdvTreeView in virtual mode in the correct way?
- when to use AddVirtualNode
- how to map between virtual and real nodes
- do you have sample code for virtual mode where adding and removing nodes is involved
- what?s the expected way of using virtual mode when adding and removing nodes is involved
Thank you