Solved

Set SelectedNode in Treeview on RightClick

Posted on 2004-08-24
2
403 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
2 Comments
 
LVL 19

Accepted Solution

by:
Desp earned 125 total points
Comment Utility
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
Comment Utility
Would have been awhile before I figured that out... Thank you.

Roger
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now