...move TreeNodes and childs at once?
Author: Benjamin Helbig
// In einem TreeView die einzelnen Knoten inklusive alles vorhandenen Child verschieben.
// Im Objektinspektor des TreeViews die Eigenschaft DragMode auf dmAutomatic stellen und unter den
// Ereignissen (OnDragDrop und OnDragOver) folgenden Code platzieren:
procedure TForm1.TreeView1DragDrop(Sender, Source: TObject; X,
Y: Integer);
var
ToDeleteItem, DropItem, CurrentItem, NextItem: TTreeNode;
ChildCount, Childrun: Integer;
begin
if Sender = Source then
begin
DropItem := TreeView1.GetNodeAt(X, Y);
CurrentItem := TreeView1.Selected;
ToDeleteItem := CurrentItem;
NextItem := TreeView1.Items.Insert(DropItem, CurrentItem.Text);
DropItem := NextItem;
ChildCount := TreeView1.Selected.Count;
for Childrun := 1 to ChildCount do
begin
CurrentItem := TreeView1.Selected.GetFirstChild;
NextItem := TreeView1.Items.AddChild(DropItem, CurrentItem.Text);
TreeView1.Items.Delete(CurrentItem);
end;
ToDeleteItem.Delete;
end;
end;
procedure TForm1.TreeView1DragOver(Sender, Source: TObject; X,
Y: Integer; State: TDragState; var Accept: Boolean);
begin
Accept := Sender = TreeView1;
end;
printed from
www.swissdelphicenter.ch
developers knowledge base