Results 1 to 6 of 6

Thread: [RESOLVED] TreeView right mice button click

  1. #1

    Thread Starter
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Resolved [RESOLVED] TreeView right mice button click

    When you right click your mice over some Node in a TreeView it gets selected for a brief moment (talking about the region that is not the "Text" of that Node - if you have FullRowSelect at True of course).

    I know there is a way i can keep it selected, just don't know how

    Thanks!

    -gav

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: TreeView right mice button click

    Do you have "HideSelection" set to False?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: TreeView right mice button click

    On a right mouse click, the DropHighlight property is set to the node that was clicked upon but only within the MouseUp event. It does not matter if FullRowSelect is true or false.

    Code:
    Private Sub TreeView1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
        If Button = vbRightButton Then
            If Not TreeView1.DropHighlight Is Nothing Then
                TreeView1.DropHighlight.Selected = True
            End If
        End If
    End Sub
    If you need to find the clicked upon node in the MouseDown event use this code

    Code:
    Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
        Dim lngIdx As Long
        Dim oNode As Node
    
        If Button = vbRightButton Then
    
            Set oNode = TreeView1.HitTest(x, y)
    
            If oNode Is Nothing Then
                'click did not occur directly on a node's text
                'check if it may have occurred elsewhere along the node's row
                For lngIdx = 1 To TreeView1.Width Step 100
                    Set oNode = TreeView1.HitTest(lngIdx, y)
                    If Not oNode Is Nothing Then
                        oNode.Selected = True
                        Exit For
                    End If
                Next
            Else
                oNode.Selected = True
            End If
        End If
    End Sub

  4. #4

    Thread Starter
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: TreeView right mice button click

    Quote Originally Posted by RobDog888
    Do you have "HideSelection" set to False?
    It doesn't matter. HideSelection only hides (if set to True) the "selection" of the selected item when TV looses focus. That's not my problem

  5. #5

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] TreeView right mice button click

    You win some, you lose some.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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