Treeview Drag n Drop

T

Terry Holland

Im writing my first Drag n Drop code Treeview in a WinForm application.

If hunted around and the following code

Private TreeView1_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles TreeView1.DragDrop
Label1.Text = TreeView1.GetNodeAt(e.X, e.Y).FullPath
End Sub

This displays the FullPath of the node that the mouse is over when the left
mouse button is released.
What I want to do is determine which node the mouse is over whilst the mouse
is moving. I want to do this because, based on the node contents, I need to
change the DragDropEffects. I dont seem to be able to accurately determine
this.

Ive tried picking up the co-ords during mouse move but the location is not
updated whilst in drag mode.

Im sure this should be quite a simple thing to do but I'd appreciate some
sample code to get me on my way

Thanks

Terry
 
P

pbhonl

Hi Terry,

This code works for me..

Private Sub TreeView1_DragOver(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles TreeView1.DragOver

Dim pt As System.Drawing.Point = CType(sender,
TreeView).PointToClient(New System.Drawing.Point(e.X, e.Y))
Dim targetNode As TreeNode = Me.TreeView1.GetNodeAt(pt)

If targetNode Is Nothing = False Then
If targetNode.Text = ??? Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If

Label1.Text = targetNode.Text

End If


End Sub
 

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