whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1548)

Database (90)
Files (137)
Forms (107)
Graphic (116)
IDE (21)
Indy (5)
Internet / LAN (131)
IntraWeb (0)
Math (76)
Misc (127)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (268)
VCL (243)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

19 Visitors Online


 
...move TreeNodes and childs at once?
Autor: Benjamin Helbig
Homepage: http://www.crash-tech.net
[ Print tip ]  

Tip Rating (14):  
     


// 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;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners