determining a treeview node droped onto

B

Brian Henry

how do you determin what tree node something was drug onto? When I use the
e.x and e.y to get the current node at that point useing GetNodeAt, the e.X
and e.Y are not coordinates on the treeview, but what looks to be a screen
coordinate. But when I do the same thing with a right click to determin what
node was right clicked on the e.X and e.Y are the right coordinates... so
what would drag drop give me different ones? and how should I figure out
what node it was dropped onto? because selectednode also doesnt tell me, but
the last node i selected.
 
A

alantolan

how do you determin what tree node something was drug onto?


I needed to convert to client co-ords and offset into the control

Private Sub TreeViewDragDropHandler( _
ByVal src As Object, _
ByVal e As DragEventArgs _
)
Dim tgtNode As TreeNode = GetTreeNodeAt(CType(src, TreeView), New
Point(e.X, e.Y))

' do whatever with the treeNode
'....

End Sub


Private Function GetTreeNodeAt( _
ByVal sender As TreeView, _
ByVal pt As Point _
) As TreeNode

Dim clientPos As Point = PointToClient(pt)
clientPos.Offset(-sender.Location.X, -sender.Location.Y)

Return sender.GetNodeAt(clientPos)

End Function

HTH

Alan.
 

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