Delphi-Quellcode:
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;
Aufruf:
Delphi-Quellcode:
var LDestNode: TTreeNode;
begin
LDestNode := FindRootNode('Kategorie1', TreeView1);
if LDestNode <> nil then
begin
TreeView1.Items.AddChild(LDestNode, 'Untereintrag1');
TreeView1.Items.AddChild(LDestNode, 'Untereintrag1');
end;
end;
[Edit2]Um allen Kritiken gerecht zu werden zur Funktion umgebaut[/Edit2]