?
Solved

Right click on TreeView Node

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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month10 days, 1 hour left to enroll

762 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