Hi,
I am trying to get familiar with the treeview component.
What I basically try to do is dynamically create 3 root nodes. Add 2 nodes to the first rood node and add nodes to these nodes (3rd level). This third level also needs to get the Data property filled.
for example something like this:
node -- node -- node
| | -- node
| node -- node
| -- node
|
node -- node
|
node
this what I have:
The first part works well, the second part (using AddObject) not. What I can't figure out is how to access a node (in this example the nodes 'type 1' and 'type 2') and add a child note using AddObject. In the example above the node is added to the node 'messages' instead of to 'type 1'.
Anyone can help me with this?
thanks!
I am trying to get familiar with the treeview component.
What I basically try to do is dynamically create 3 root nodes. Add 2 nodes to the first rood node and add nodes to these nodes (3rd level). This third level also needs to get the Data property filled.
for example something like this:
node -- node -- node
| | -- node
| node -- node
| -- node
|
node -- node
|
node
this what I have:
Code:
procedure TForm1.FormShow(Sender: TObject);
var MyTreeNode1, MyTreeNode2,MyNode: TTreeNode;
MyRecPtr: PMyRec;
begin
with TreeView.Items do
begin
MyTreeNode1 := Add(nil, 'Messages');
AddChild(MyTreeNode1,'Type 1');
AddChild(MyTreeNode1,'Type 2');
MyTreeNode1 := Add(nil, 'Signatures');
MyTreeNode1 := Add(nil, 'Accounts');
end;
New(MyRecPtr);
MyRecPtr^.FName := 'checking data 1';
MyRecPtr^.LName := 'checking data 2';
MyTreeNode2 := TreeView.Items[0].Item[0];
TreeView.Items.AddObject(MyTreeNode2, 'Item 1', MyRecPtr);
end;
The first part works well, the second part (using AddObject) not. What I can't figure out is how to access a node (in this example the nodes 'type 1' and 'type 2') and add a child note using AddObject. In the example above the node is added to the node 'messages' instead of to 'type 1'.
Anyone can help me with this?
thanks!