Solved

Set SelectedNode in Treeview on RightClick

Posted on 2004-08-24
2
416 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

734 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