Solved

Set SelectedNode in Treeview on RightClick

Posted on 2004-08-24
2
415 Views
Last Modified: 2008-01-16
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
Comment
Question by:rdavis101
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 19

Accepted Solution

by:
Desp earned 125 total points
ID: 11881199
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
 

Author Comment

by:rdavis101
ID: 11881699
Would have been awhile before I figured that out... Thank you.

Roger
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question