Consulting

Results 1 to 12 of 12

Thread: TreeView

  1. #1
    VBAX Regular
    Joined
    Dec 2004
    Posts
    93
    Location

    Question TreeView

    Hi there,

    I am trying to get the value (or text) of the Node when I double click on the treeView. So far no luck. Can you help to write a code in VBA?

    I tried this but it does not work:

    Private Sub treeView1_DblClick() 
    MsgBox Node.Text
    End Sub

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Try the NodeClick event instead.

    Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node) 
    Me.Caption = Node.Text 
    End Sub

  3. #3
    VBAX Regular
    Joined
    Dec 2004
    Posts
    93
    Location
    Jacob,

    I tryed this but this is what I get:

    Copile Error:
    Procedure declaration does not match description of event or procedure have the same name.

  4. #4
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Can you post an attachment with your workbook?

    Check your code to make sure that there are no subs with the same name.

  5. #5
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Also to be sure that the code is correct for your version on Excel. Select TreeView1 from the left drop down on the Code Window in the VBE. And select NodeClick from the right drop down. The correct names for the sub and the arguments will be written in for you.

  6. #6
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    You can download a TreeView Control example here.

  7. #7
    VBAX Regular
    Joined
    Dec 2004
    Posts
    93
    Location
    Strange, but that is exactly what I was doing. Still does not work. There is no other procedures with the same name.
    Is there a way to attach a workbook with the code?

  8. #8
    VBAX Regular
    Joined
    Dec 2004
    Posts
    93
    Location
    But your example works for one click. I need it working on double click.

  9. #9
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Quote Originally Posted by Kaizer
    Strange, but that is exactly what I was doing. Still does not work. There is no other procedures with the same name.
    Is there a way to attach a workbook with the code?
    Click on "Post Reply" and scroll down to where it says "Manage Attachments". You need to zip the workbook first then you can upload it.

  10. #10
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Quote Originally Posted by Kaizer
    But your example works for one click. I need it working on double click.
    Ok, I think I understand what you want to do now. Try this:


    Option Explicit
    Dim NodeValue       As String
      
     Private Sub TreeView1_DblClick()
    Me.Caption = NodeValue
    End Sub
      
     Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
    NodeValue = Node.Text
    End Sub

  11. #11
    VBAX Regular
    Joined
    Dec 2004
    Posts
    93
    Location
    Jacob,

    Thank you. It works. I guess there is no need to attach the file.

  12. #12
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    You're Welcome

    Take Care

Posting Permissions

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