Solved

Right Click on Treeview Node and get popup menu

Posted on 2002-07-12
8
562 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 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Revamp Your Training Process

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

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month8 days, 11 hours left to enroll

617 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