Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GetNodeAt function of a Treeview

Status
Not open for further replies.

FederalProgrammer

Programmer
Jul 2, 2003
318
CA
I have a Treeview w/ a bunch of dynamically created nodes and sub-nodes;
I have implemented the dragdrop functionality for this treeview.

My problem is in this following function:

Private Sub trvViews_DragOver(ByVal o As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles trvViews.DragOver
e.Effect = DragDropEffects.Move

Me.trvViews.SelectedNode = Me.trvViews.GetNodeAt(e.X, e.Y)

End Sub

The selected node (highlighted node) is not actually the one that is being pointed to by the cursor!! There's always a 7 node difference; To see what I mean consider the following example:
Node A1
subNodeA2
subNodeA3
subNodeA4
subNodeA5
Node B1
subNodeB2
Node C1
subNodeC2
subNodeC3

when I drag the cursor to "Node A1", "Node C1" gets highlighted; has anyone seen this? or can you think of why this is the case??

cheers!



why do they call it VB.NET? it's nothing like vb; they should've called it B#!!
 
I found the solution...
here's what should be done:

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

e.Effect = DragDropEffects.Move

' Retrieve the client coordinates of the mouse position.
Dim targetPoint As Point = Me.trvViews.PointToClient(New Point(e.X, e.Y))
Me.trvViews.SelectedNode = Me.trvViews.GetNodeAt(targetPoint)
Me._selectedNode = Me.trvViews.SelectedNode

End Sub

Good luck!

why do they call it VB.NET? it's nothing like vb; they should've called it B#!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top