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
Solved

Set SelectedNode in Treeview on RightClick

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 (3.5 Framework) Remove all items from List 3 32
VB.net and sql server 4 45
Optimize the query 5 43
Open a link in vb.net 2 16
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

829 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