procedure TForm1.Button1Click(Sender: TObject);
// TreeView1.Selected => TreeView2's RootNode
var
Item: TTreeNode;
begin
if (TreeView1.Selected <> nil) then
begin
Item := TreeView2.Items.Add(nil, '');
Item.Assign(TreeView1.Selected);
procedure TForm1.CopyChildNode(SourceTreeView, DestTreeView: TTreeView; Source, Dest: TTreeNode);
var
Index: Integer;
Item: TTreeNode;
begin
for Index := 0 to Source.Count - 1 do
begin
// Copies Node
Item := DestTreeView.Items.AddChild(Dest, '');
Item.Assign(Source[Index]);
// Copy Child Nodes
if Source.Item[Index].HasChildren then
CopyChildNode(SourceTreeView, DestTreeView, Source[Index], Item);
end;
// Deletes Node
for Index := Source.Count - 1 to 0 do
SourceTreeView.Items.Delete(Source[Index]);
end;
그냥 재귀호출써서 모두 복사하시면 될텐데요...
procedure TForm1.Button1Click(Sender: TObject);
// TreeView1.Selected => TreeView2's RootNode
var
Item: TTreeNode;
begin
if (TreeView1.Selected <> nil) then
begin
Item := TreeView2.Items.Add(nil, '');
Item.Assign(TreeView1.Selected);
CopyChildNode(TreeView1, TreeView2, TreeView1.Selected, Item);
TreeView1.Items.Delete(TreeView1.Selected);
end;
end;
procedure TForm1.CopyChildNode(SourceTreeView, DestTreeView: TTreeView; Source, Dest: TTreeNode);
var
Index: Integer;
Item: TTreeNode;
begin
for Index := 0 to Source.Count - 1 do
begin
// Copies Node
Item := DestTreeView.Items.AddChild(Dest, '');
Item.Assign(Source[Index]);
// Copy Child Nodes
if Source.Item[Index].HasChildren then
CopyChildNode(SourceTreeView, DestTreeView, Source[Index], Item);
end;
// Deletes Node
for Index := Source.Count - 1 to 0 do
SourceTreeView.Items.Delete(Source[Index]);
end;
^^ 항상 즐코하세요...