Solved

Right Click on Treeview Node and get popup menu

Posted on 2002-07-12
8
523 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
  • 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 60 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
 
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now