Board index » delphi » Detecting a Node in OnDragOver

Detecting a Node in OnDragOver

I gave an OnDragOver event that I want to use to stop users from
dragging a node in a treeview to itself, the nodes parent or one of the
nodes children.  I can stop it being dropped on itself and its parent
but I am having difficult detecting that the target node is a child of
the selected node. I have tried the following two methods. The first
method appear to get into a loop and the second still allows the node to
be dropped.
1.
Accept := false;
if TreeView1.GetNode(X,Y).Parent.Text <> TreeView1.Selected.Text then
        Accept := true;

2.
if TreeView1.GetNodeAt(X,Y).HasAsParent(TreeView1.Selected) then
        Accept := false
else
        Accept := true;

Any ideas?

 

Re:Detecting a Node in OnDragOver


Quote
In article <35D233A3.5...@swiftscan.com>, Simon Bowyer wrote:
> I can stop it being dropped on itself and its parent
> but I am having difficult detecting that the target node is a child of
> the selected node

I do it by using GetNodeAt in the mousedown event to save the original
node and use something like:

  while newnode.Parent <> nil do begin
    if newnode.HasAsParent(orignode) then Break;
    newnode := newnode.Parent;
  end;
  Accept := (newnode.Parent=nil);

 Mike Orriss (ICQ 17069815)
 http://www.3kcc.co.uk/notetree.htm

Other Threads