In TtreeView1.DragDrop am using statements such as
targetnode := TreeView1.GetNodeAt(x,y);
...
TreeView1.Selected.MoveTo(targetnode , naInsert ) ;
to move a node with the mouse and insert it in front of ie above, an existing node on the same level.
Id like to change the behaviour so that if I am dragging downwards the node gets moved to below the target but if I am dragging upwards it gets moved to above the target (otherwise I can drag to a new bottom position but not a new top or vice versa). The sort of structure I am trying is
targetnode := TreeView1.GetNodeAt(x,y);
...
if DraggedItem.Index > targetnode.Index then //we are dragging upwards, insert before
TreeViewStructure.Selected.MoveTo(targetnode , naInsert )
else //we are dragging downwards, insert after
TreeViewStructure.Selected.MoveTo(targetnode , ???) ;
but I cannot find a TNodeAttachMode constant that inserts a sibling after the target node. The constants for TNodeAttachMode given here http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/ComCtrls_TNodeAttachMode.html are ...
naAdd: The new or relocated node becomes the last sibling of the other node.
naAddFirst: The new or relocated node becomes the first sibling of the other node.
naInsert:The new or relocated node becomes the sibling immediately before the other node.
naAddChild:The new or relocated node becomes the last child of the other node.
naAddChildFirst:The new or relocated node becomes the first child of the other node.
but none of those refer to a new last sibling.
Can I do what I want? if so how?
There is no option to insert after a node, only insert before. So you have to find the node after the drop target, and insert before it.
To add after the last node, find the last node and pass naAdd
to MoveTo
.