TreeView.GetNodeAt problem

A

Alan T

I have a dragdrop event to capture the treenode that trigger that event.
However, I always get the returned node is null.

private void trvEmployee_DragDrop(object sender, DragEventArgs e)

{
TreeNode targetNode;

MessageBox.Show(e.X.ToString + " -- " + e.Y.ToString());
targetNode = trvEmployee.GetNodeAt(e.X, e.Y);
if (targetNode == null)
{ MessageBox.Show(" null");
}
else
{ MessageBox.Show(target.Text);
}
}

I don't know why it showed the e.X and e.Y have valid values but the
targetNode is null.

However, if I hardcode the
targetNode = trvEmployee.GetNodeAt(e.X, e.Y);
to e.X and e.Y to some value, it showed the node.
Note, the AllowDrop perperty has been set to true already.
 
M

Michael

When you receive your coordinates, they're actually with respect to the
screen. For you treeview to understand you need to change them to the
"client" equvalent.

Point newPoint = treeView1.PointToClient( new Point(e.X, e.Y));

MessageBox.Show(e.X.ToString() + " -- " + e.Y.ToString());

targetNode = treeView1.GetNodeAt(newPoint.X, newPoint.Y);

if (targetNode == null)

Mike

http://www.seeknsnatch.com
 
A

Alan T

Hi thanks.
I tried using one statement:
targetNode = treeView1.GetNodeAt(newPoint(e.X, e.Y));

Is there any differences from yours ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top