delphi TreeView - create nodes at run-time

delphi, treeview

Solution

Adding nodes:

function FindRootNode(ACaption: String; ATreeView: TTreeView): TTreeNode; 
var LCount: Integer; 
begin 
  result := nil; 
  LCount := 0; 
  while (LCount < ATreeView.Items.Count) and (result = nil) do 
  begin 
    if (ATreeView.Items.Item[LCount].Text = ACaption) and (ATreeView.Items.Item[LCount].Parent = nil) then 
      result := ATreeView.Items.Item[LCount]; 
    inc(LCount); 
  end; 
end;

...

var LDestNode: TTreeNode; 
begin 
  LDestNode := FindRootNode('category', TreeView1); 
  if LDestNode <> nil then 
  begin 
    TreeView1.Items.AddChild(LDestNode, 'node1'); 
    TreeView1.Items.AddChild(LDestNode, 'node2'); 
  end; 
end;

(see also http://msdn.microsoft.com/en-us/library/70w4awc4.aspx)

Disabeling a node

As far as I know, there is no way to disable a TreeNode. Only thing you could do is intercept the beforeSelect-event and cancel the selection there. Not so nice.

Problem

Can anybody tell me how to do the following: - Create Nodes - Enable/Disable Individual Nodes I want to know how to do the above at Application run-time, eg in the Form's OnCreate event.

Original source

Related problems