Google
 

Sunday, November 11, 2007

Drag'n'Drop nodes inside TreeView

The following code uses GetNodeAt to add a dragged node as a child of the node under then mouse when it is dropped.

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

No comments: