Solved

Right Click on Treeview Node and get popup menu

Posted on 2002-07-12
8
542 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…

839 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