# VBForums CodeBank > CodeBank - Other >  [Delphi 7] - D&D Treeview nodes

## Madboy

```
procedure TForm1.TreeView1DragDrop
(Sender, Source: TObject; X, Y: Integer) ;
var
   AnItem: TTreeNode;
   AttachMode: TNodeAttachMode;
   HT: THitTests;
begin
   if TreeView1.Selected = nilthen Exit;
   HT := TreeView1.GetHitTestInfoAt(X, Y) ;
   AnItem := TreeView1.GetNodeAt(X, Y) ;
   if (HT -
     [htOnItem, htOnIcon, htNowhere, htOnIndent]
<> HT) then
   begin
     if (htOnItem in HT) or
        (htOnIcon in HT) then
         AttachMode := naAddChild
     else if htNowhere in HT then
AttachMode := naAdd
     else if htOnIndent in HT then
AttachMode := naInsert;
     TreeView1.Selected.
MoveTo(AnItem, AttachMode) ;
   end;
end;
```

----------

