Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add nodes to FireMonkey's TreeView at runtime

I can't found any sample in the online documentation, or in the demos included with Delphi XE2, for adding nodes to a FMX.TreeView.TTreeView control at runtime. So, how can I add, remove, and traverse nodes of a FireMonkey TreeView at runtime?

like image 812
Salvador Avatar asked Sep 21 '11 23:09

Salvador


1 Answers

I think we are all learning at this point...

But from what I have seen the TTreeView use the principle that any control can parent another control.

All you need to do is set the Parent Property to get the item to show up as a child.

var
  Item1 : TTreeViewItem;
  Item2 : TTreeViewItem;
begin
  Item1 := TTreeViewItem.Create(Self);
  Item1.Text := 'My First Node';
  Item1.Parent := TreeView1;

  Item2 := TTreeViewItem.Create(Self);
  Item2.Text := 'My Child Node';
  Item2.Parent := Item1;
end;

Because of this you can do things never possible before, such as placing any control in the TreeView. For example this code will add a button to the area used by Item2, and the button won't be visible until the Item2 is visible.

  Button := TButton.Create(self);
  Button.Text := 'A Button';
  Button.Position.X := 100;
  Button.Parent := Item2;
like image 167
Robert Love Avatar answered Sep 18 '22 21:09

Robert Love