How to create a Virtual String Tree in Delphi

1
What happens is that I created a Virtual String Tree in Delphi (Typhon64), but I do not know how to add parent and child nodes to create the tree, I looked at the documentation but only found click events that creates deletes and edits the node (node), I need to create this dynamic tree until then I can do this only that using click event and adding nodes with addChild (nil) method, but this is not what I want what I want is that as soon as load the form the Virtual String Tree already loads with the nodes and the name of the nodes and strings that I set, it does not matter if it is string or an array of strings, since it creates the tree with the parents and the children I I am very grateful for the help!

Until then my Virtual String Tree is like the image below:

link

Iwouldliketocreateatreeastheexamplebelow,butthevaluesIwilldefine:

link

    
asked by anonymous 12.05.2015 / 15:22

1 answer

0

To add a parent node declare a variable of type PVirtualNode :

pai: PVirtualNode;

Give a command to start editing the grid before starting to insert the nodes:

vstGrid.BeginUpdate;

Add the parent node this way:

pai := vstGrid.AddChild(nil, ["Conteúdo do nó"]);

To add the children pass the parent in the first parameter:

vstGrid.AddChild(pai, ["Conteúdo do nó"]);

To create this in the opening of the form, make a loop in OnShow using the commands mentioned above. This will vary depending on how you are bringing this information.

Once you have finished inserting the nodes, give the command to finish editing the grid:

vstGrid.EndUpdate;

If you want to bring the expanded nodes use the command:

vstGrid.FullExpand;
    
16.05.2017 / 22:55