Drag Drop Woes

B

bob

Hi,
VS2008
Trying to implement a simplified version of Mike Gold's tutorial on
Drag Drop.
My problem is that the dragover event handler never appears to pass
over a node.
I move the 'envelope' all over the tree view but FindTreeNode always
returns null.
The event handler e member appears to contain legiitimate X,Y
co-ordinates but myTreeView.GetNodeAt(X,Y) always returns null;
Any clues as to what I am doing wrong?
thanks
Bob
Code follows:
private void tvInstallation_DragOver(object sender, DragEventArgs e)
{
//Point p = new Point(e.X,e.Y);
TreeNode aNode = FindTreeNode(e.X, e.Y);
if(aNode!=null)
{
aNode.BackColor = Color.DarkBlue;//NEVER GET HERE
}
}

private TreeNode FindTreeNode(int X,int Y)
{

return tvInstallation.GetNodeAt(X,Y); //Getting Called but
always returning null

}
 
B

bob

[...]
The event handler e member appears to contain legiitimate X,Y
co-ordinates but myTreeView.GetNodeAt(X,Y) always returns null;
Any clues as to what I am doing wrong?

Why do the coordinates appear legitimate to you?

According to MSDN (always a good place to look when things aren't working
as you expect), the X and Y properties of DragEventArgs are given in
screen coordinates. You need to convert them to client coordinates, using
the PointToClient() method of your control, before passing them to
GetNodeAt().

Pete

Right on the money Pete.
Thanks.
Bob.
 

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

Top