[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 471
  • Last Modified:

Set SelectedNode in Treeview on RightClick

I have a treeview and a context menu. When I right click on a node, it becomes highlighted, and my a context menu appears. So far so good. However, when I msgbox the text of the node, it tells me that the selected node is not the one highlighted. IF YOU POPUP A CONTEXT MENU, THE HIGHLIGHTED NODE WILL CHANGE WITHOUT CHANGING THE SELECTED NODE.

How can I change the selected node to the node highlighted on right click?



0
rdavis101
Asked:
rdavis101
1 Solution
 
Fahad MukhtarDistinguished EngineerCommented:
put this code in the TreeView1_MouseUp event .. this code will select the rightclicked node and display the context menu at the point of right click

    Private Sub TreeView1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TreeView1.MouseUp

        If e.Button = MouseButtons.Right Then
            TreeView1.SelectedNode = TreeView1.GetNodeAt(e.X, e.Y)

        End If

        If TreeView1.SelectedNode Is Nothing Then
            Exit Sub
        End If

        Dim spot As Point = Me.PointToClient(TreeView1.PointToScreen(New Point(e.X, e.Y)))
        ContextMenu1.Show(Me, spot)
    End Sub
0
 
rdavis101Author Commented:
Would have been awhile before I figured that out... Thank you.

Roger
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now