Solved

Right click on TreeView Node

Posted on 1999-01-12
3
415 Views
Last Modified: 2010-05-03
How do I to get a right click on a treeview node to behave like a left click in that it will highlight the node selected by the right click action?  

Upon a right click I display a popup menu. Currently if I right click on a node which is not currently highlighted, it will display the menu for the node that is highlighted, and not the one I am clicking.

This would seem a reasonable thing to do as this is how it currently works in Windows explorer.  ie) if you click on  an item, then right click on a different item, the new item you right clicked will be highlighted, and the popup menu will be displayed for the new item.
0
Comment
Question by:wfinn
[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
3 Comments
 
LVL 8

Accepted Solution

by:
MikeP090797 earned 100 total points
ID: 1455857
Try this:
in TreeView1_MouseDown:
IF Button=2 then Set Treeview1.SelectedItem = TreeView.HitTest(X, Y).
'Display menu here
0
 

Author Comment

by:wfinn
ID: 1455858
The proposed answer is good.  However, it still behaves differently than in Windows Explorer.  That is, if I right click and the menu appears, I can not right click on another node.  However, in Explorer, I can right click on a node, then immediately right click on another.  If I select the wrong node with the right click and then decide I need to select another node, I have to left on something else first, then right click.
0
 
LVL 1

Expert Comment

by:twolff
ID: 1455859
Here is something that I worked up. This should help you:
    With TreeView1
        Set .SelectedItem = .HitTest(x, y)
    End With
    If Button = 2 Then
        PopupMenu mnu1, vbPopupMenuRightButton, x, y
    End If

The PopupMenu procedure only works with the left button by default. If you include the flag vbPopupMenuRightButton it will also work with the right button. This will allow the mousedown to event to fire on the treeview and will automatically hide the popup menu. Enjoy!
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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

707 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