Na, dann so in etwa:
Delphi-Quellcode:
procedure AssignChildren(Source, Dest : TTreeNode);
var
subtn : TTreeNode;
i : integer;
begin
Dest.DeleteChildren;
for i := 0 to (Source.Count-1) do
If (Source.Item[i].Parent = Source) then
begin
subtn := TTreeView(Dest.TreeView).Items.AddChild(Dest, '');
subtn.Assign(Source.Item[i]);
If Source.Item[i].HasChildren then
AssignChildren(Source.Item[i], subtn);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i : integer;
tn : TTreeNode;
begin
for i := 0 to (TreeView1.Items.Count-1) do
begin
If TreeView1.Items[i].Parent = nil then
begin
tn := TreeView2.items.AddChild(TreeView2.items[0], '');
with tn do
begin
Assign(TreeView1.Items[i]);
If TreeView1.Items[i].HasChildren then
AssignChildren(TreeView1.Items[i], tn);
end;
end;
end;
If Assigned(TreeView1.Images) then
begin
If not Assigned(TreeView2.Images) then
TreeView2.Images := TImageList.Create(nil);
TreeView2.Images.AddImages(TreeView1.Images);
end;
If Assigned(TreeView1.StateImages) then
begin
If not Assigned(TreeView2.StateImages) then
TreeView2.StateImages := TImageList.Create(nil);
TreeView2.StateImages.AddImages(TreeView1.StateImages);
end;
end;
In dem Fall ist TreeView1 einer der versteckten TVs und TreeView2 ist derjenige, der die Untereinträge bekommt.