This seems like it should be easy to do but has me stumped.
I have a treeview. I want to create a right-click context menu whereby the user can add or delete a node. I am having trouble just identifying the node that the user right clicked.
Here is my code so far. (Right now, I am just trying to display the node name in a text box. If I can get that to work, the add/delete logic is easy).
I am using global variables to track mouse position as the contextmenu popup event doesn't appear to provide the location. But this isn't working correctly. Basically, the location is wrong.
In fact, I'd prefer to do it without the global variables, but will settle for any way of getting it to work right now.
Private Sub ContextMenu1_Popup(ByVal sender As Object, ByVal e As System.EventArgs) Handles ContextMenu1.Popup
MsgBox(TreeView1.GetNodeAt(TreeView1.PointToScreen(New Point(MouseUpX, MouseUpY))).Text)
Private Sub TreeView1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TreeView1.MouseDown
MouseUpX = e.X
MouseUpY = e.Y()