Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Right Click on Treeview Node and get popup menu

Posted on 2002-07-12
8
Medium Priority
?
573 Views
Last Modified: 2012-05-04
In Access 2000 I have a treeview control and many nodes. I want to be able to right click on any node, and have a popup menu display. I already made the menu, i just need to know how to be able to right click on a node. As of now if i left or right click it just selects a node.

For example, if you go into Windows Explorer and right click, you get a menu with options. I want my treeview nodes right click to work like that.
0
Comment
Question by:CyberAccess
[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
  • 4
  • 3
8 Comments
 
LVL 5

Expert Comment

by:rpai
ID: 7150036
Public Sub TreeView1_NodeClick(ByVal Node as MSComctlLib.Node)

 Load mnuPopUp '-- mnuPopUp is the name of the menu you created.

End Sub
0
 
LVL 5

Accepted Solution

by:
RainUK earned 180 total points
ID: 7152110
Hi CyberAccess

Try the code below, in the MouseDown event of the treeview control you are using:

BEGIN CODE ---------------------------------------------

Private Sub TreeView1_MouseDown(Button as Integer, Shift as Integer, x As Single, y As Single)


Dim nodeItem as Node

    If Button = vbRightBUtton Then

        Set nodeItem = TreeView1.HitTest(x,y)
        If NOT(nodeItem Is Nothing) Then
            PopupMenu NameOfYouPopupMenu
        End If
 
    End If

End Sub

END CODE-----------------------------------------------

This code simply uses the treeview mousedown event to check firstly which mouse button was clicked, and then if the mouse clicl equated to clicking a node. If not then the local variable nodeItem is not set. Otherwise if the user did click a node you then get an instantiation of the nodeItem. (Which will allow you to query which node they clicked, e.g. nodeItem.Key etc) The PopupMenu command will then show the menu you created in VBs menu editor.



0
 

Author Comment

by:CyberAccess
ID: 7154104
rpai and RainUK, i tried both of your solutions and neither work. RainUK, i get an error saying mouse move this and that and that the event procedures dont match etc... when i look at my treeview event properties i dont even see a mouse down event, but my form has one. so i still put the code in but i dont think my treeview recognizes the mouse down event, any other suggestions.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 5

Expert Comment

by:RainUK
ID: 7154112
Does your tree view have a click event of some sort? Please provide me the procdure call including parameters passed.
0
 

Author Comment

by:CyberAccess
ID: 7155427
Private Sub axTreeView_NodeClick(ByVal Node As Object)
0
 
LVL 5

Expert Comment

by:RainUK
ID: 7155441
Okay sorry I assumed you were using VB. I have never done any Access forms code, is there any event in the form or in the tree view that tells you which control was clicked?

In the forms events, what is the one that is fired when you click it and also if you click the treeview, does the forms mouse click event fire before the treeview_nodeclick does if you click on the treeview?
0
 

Author Comment

by:CyberAccess
ID: 7155594
Hey, I actually got is to work but had to modify your code a bit, but it gave me some helpful insight. Thanks for the time you spent. You deserve the points. Yeah sorry i am working in access with VBA and i couldn't get any help in the access section of Experts Exchange and i figured a VB person would know more about it ;)
0
 
LVL 5

Expert Comment

by:RainUK
ID: 7155606
great news :-)
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

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…
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…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

721 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