Martin,
To add a tree node at runtime use the methods of the TTreeNodes class (AddFirst, AddChild, Add etc). For example:
procedure TForm1.Button1Click(Sender: TObject);
var
ParentNode: TTreeNode;
begin
ParentNode := MyTreeView.Items.AddFirst(nil, 'Parent Node');
MyTreeView.Items.AddChildFirst(ParentNode, 'Child Node 1');
MyTreeView.Items.AddChild(ParentNode, 'Child Node 2');
end;
If you are using the TTreeNode.Data property to attach pointers to your nodes then it is much faster to use AddChildObject than to attach the pointer after the node has been created using AddChild etc.
If you are using Oracle then you can run a query that will return data structured in a parent-child relationship using Start With and Connect By. For example:
select id, parent_id, company_name
from company
start with parent_id = 0
connect by parent_id = prior id
will return a set of companies, where any parent company has a parent_id of 0, and any child company has a parent_id equal to the id of its parent. Did that make sense? In addition to the columns specified this query will also return a column called 'level', which tells you which level of the tree the record is at. You will still need to manually loop through the query data set and add nodes to the treeview though, there is no DBTreeView component.