Solved

Right click on TreeView Node

Posted on 1999-01-12
3
409 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
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

749 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