GetNodeAt problem

  • Thread starter Thread starter Alistair George
  • Start date Start date
A

Alistair George

tvNodes is a treeview. In one program using exactly the same code, it
provides a selectednode object correctly, however in another using same
code it cannot detect which item is under the cursor.
Any idea why this should not work - I have checked out properties/events
side-by side between both treeview components and they are replicated:

private void tvNodes_DragOver(object sender,
System.Windows.Forms.DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
Point pt = PointToClient(new Point(e.X, e.Y));
TreeNode targetNode = this.tvNodes.GetNodeAt(pt);
//targetNode always returns null even though its over another node.
 
Alistair said:
tvNodes is a treeview. In one program using exactly the same code, it
provides a selectednode object correctly, however in another using same
code it cannot detect which item is under the cursor.
Any idea why this should not work - I have checked out properties/events
side-by side between both treeview components and they are replicated:

private void tvNodes_DragOver(object sender,
System.Windows.Forms.DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
Point pt = PointToClient(new Point(e.X, e.Y));
TreeNode targetNode = this.tvNodes.GetNodeAt(pt);
//targetNode always returns null even though its over another node.
Answer was:
Point pt = tvNodes.PointToClient(new Point(e.X, e.Y));
TreeNode targetNode = tvNodes.GetNodeAt(pt);
tvNodes.SelectedNode = targetNode;
 
Back
Top