Results 1 to 12 of 12

Thread: Prevent a treeview node to collapse on double-click

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Posts
    21
    Hi,

    Does somebody knows how to prevent a treeview parent node from collapsing on double-click.

    I would like to launch something on double click of my nodes but make it impossible to collapse/expand nodes except from the plus/minus sign box.

    I know I can probably do it by using subclassing. What I am looking for is the message I have to intercept.

    Thanks in advance!

    Tipi

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Try this
    Code:
    Private Sub Form_Load()
        TreeView1.Nodes.Add TreeView1.Nodes.Add(, , , "A"), 4, , "b"
    End Sub
    
    Private Sub TreeView1_Collapse(ByVal Node As MSComctlLib.Node)
        Node.Child.EnsureVisible
    End Sub
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Posts
    21
    Not exactly the solution I was looking for since I want to be able to expand/collapse using plus/minus sign...

    Thanks,

    Tipi

    [Edited by Tipi on 05-30-2000 at 11:11 AM]

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Posts
    21

    Final Answer

    Code:
    'This code goes in form
    Private Sub Form_Load()
      Hook TreeView1.hWnd
    End Sub
    
    Private Sub Form_Unload()
      Unhook TreeView1.hWnd
    End Sub
    
    
    'This code goes in module
    Option Explicit
    
    Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    
    
    Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    
    Public Const WM_LBUTTONDBLCLICK = &H203
    
    
    Function WindowProcedure(ByVal hw As Long, ByVal uMsg As _
        Long, ByVal wParam As Long, ByVal lParam As Long) As _
        Long
    
    If uMsg = &H203 Then
      Call DoWhatYouWant
      Exit Function
    End If
    
    WindowProcedure = CallWindowProc(lpPrevWndProc, hw, _
    uMsg, wParam, lParam)
    End Function
    
    Public Sub Hook(hWnd As Long)
        lpPrevWndProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProcedure)
    End Sub
    
    Public Sub Unhook(hWnd As Long)
        Dim temp As Long
        temp = SetWindowLong(hWnd, GWL_WNDPROC, lpPrevWndProc)
    End Sub

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Sorry i didn't test that code, this shoud work:
    [/code]
    Private stage%
    Private Sub Form_Load()
    TreeView1.Nodes.Add TreeView1.Nodes.Add(, , , "A"), 4, , "b"
    End Sub

    Private Sub TreeView1_Collapse(ByVal Node As MSComctlLib.Node)
    If stage = 1 Then stage = 2: Node.expanded = True: TreeView1.Tag = ""
    End Sub

    Private Sub TreeView1_Expand(ByVal Node As MSComctlLib.Node)
    If stage = 1 Then stage = 2: Node.Expanded = False: TreeView1.Tag = ""
    End Sub

    Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
    stage = 1
    End Sub
    [/code]
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    try this:

    Code:
    Option Explicit
    Private Sub Form_Load()
    tv1.Nodes.Add , , "main", "Hey"
    tv1.Nodes.Add "main", tvwChild, "child", "Hey1"
    End Sub
    
    Private Sub tv1_Click()
    tv1.SelectedItem.Expanded = True
    
    End Sub
    
    Private Sub tv1_Collapse(ByVal Node As MSComctlLib.Node)
    Node.Image = "closed"
    End Sub
    Private Sub tv1_DblClick()
    tv1.SelectedItem.Expanded = False
    End Sub
    
    Private Sub tv1_Expand(ByVal Node As MSComctlLib.Node)
    Node.Image = "open"
    End Sub

  7. #7
    Fanatic Member SkiNLaB's Avatar
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    747
    whats "Private stage%" do ??

    edit: thanks 2 whoever wrote the sol. its in good use
    Last edited by SkiNLaB; May 25th, 2004 at 07:45 PM.

  8. #8
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    Originally posted by SkiNLaB
    whats "Private stage%" do ??

    edit: thanks 2 whoever wrote the sol. its in good use
    Nice sig

    VB Mods...might want to fix that...or encrypt the data :-)

  9. #9
    Fanatic Member SkiNLaB's Avatar
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    747
    Originally posted by jhermiz
    Nice sig

    VB Mods...might want to fix that...or encrypt the data :-)
    they already pulled me up about it, and told me to add "Ignoring arc" so that the user was aware what the link was doing...

  10. #10
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    Originally posted by SkiNLaB
    they already pulled me up about it, and told me to add "Ignoring arc" so that the user was aware what the link was doing...
    whose arc ?

  11. #11
    Fanatic Member SkiNLaB's Avatar
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    747
    Originally posted by jhermiz
    whose arc ?
    an [edited by moderator] right wing [edited by moderator] who thinks that every american should live like a king and [edited by moderator] the rest of the world.

    thats if my memory serves me correctly.

  12. #12

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