Solved

Right Click on Treeview Node and get popup menu

Posted on 2002-07-12
8
548 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual Basic Excel Formatting error 4 141
MS Date Picker 64 bit 32 bit issue 12 64
Macro Excel - Multiple If conditions 2 88
MsgBox 4 71
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

726 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