Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Right click on TreeView Node

Posted on 1999-01-12
3
Medium Priority
?
422 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 300 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

609 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