You canot change the index of a node. Normally when using VirtualStringTree
you hold your data in your own data structure separate from the tree and access the data from the events.
You can also store data directly in the nodes (using a record), but I prefer the other approach because it keeps the logic out of the tree view.
For example, you could store the data in a list and access this list in the GetText
handler (you can use Node.Index
). Then, if you want to reorder the items, just reorder your list and everything else will happen automatically (you might have to call Invalidate
on the tree).
Pseudocode:
Initializing:
Tree.RootNodeCount := MyList.Count;
In the GetText
event:
NodeText := MyList [Node.Index];
Reordering:
Reorder (MyList);
Tree.Invalidate;