Results 1 to 7 of 7

Thread: right click on a tree view node

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2000
    Location
    Nashville, TN
    Posts
    54
    I can do the code for a normal click on tree view but what about right click, thanks for any help

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    What exactly do you mean? If you mean that you want to trap the Node you clicked on, then you can use NodeClick event, which has 1 argument - Node object that represents the node you clicked.

    If you mean something different, please rephrase.

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2000
    Location
    Nashville, TN
    Posts
    54
    Sorry for the confusion, Yes I want to trap the node on a right click, for example, lets say I have a node that is call desserts, and this node has three child nodes. One of the child nodes is called Chocolate Cake, whe the user right clicks on this child node I want to execute some code. I know how to do the NodeClick(ByVal Node As MSComctlLib.Node), but this is for either left or right click, any way to keep it to right only, thanks again

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    This can be solved by co-operating with another event:

    Private Sub tvtree_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    tvtree.Tag = Button
    End Sub

    Private Sub tvtree_NodeClick(ByVal Node As ComctlLib.Node)
    Select Case Val(tvtree.Tag)
    Case 1
    MsgBox "Left click"
    Case 2
    MsgBox "Right click"
    End Select
    End Sub

    Hope this works!

  5. #5
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Node click doesn't care what button you clicked with. What you can do is to use a MouseDown event to check if the user clicked with the right mouse button and then fire your function (or whatever you have there setup)
    Code:
    Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
        Dim nodCurrent As Node
        
        If Button = vbRightButton Then
            Set nodCurrent = TreeView1.HitTest(x, y)
            If Not nodCurrent Is Nothing Then
                nodCurrent.Selected = True
                MsgBox "You right clicked on " & nodCurrent.Text
            End If
        End If
    End Sub

  6. #6

    Thread Starter
    Member
    Join Date
    Feb 2000
    Location
    Nashville, TN
    Posts
    54
    thanks alot guys

  7. #7
    Fanatic Member
    Join Date
    Jan 1999
    Location
    UK
    Posts
    554
    I think a better way is use a menu on a hidden form (a form that will not be visible when the application is run but will be loaded none-the-less) and then to use the popupmuenu command to popup the menu which is on the hidden form, that way you can set the event code for as many options as you like.

    Doc Zaf
    {;->

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width