Results 1 to 12 of 12

Thread: [RESOLVED] TreeView Problem...

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    27

    Resolved [RESOLVED] TreeView Problem...

    I'm using the good ol treeview and I can get everything else to seem to work with it except i want to make 1 of the nodes a weblink so when it's clicked it just opens up the page.

    I have the code attached to a label right now and it works great... it opens up the default browser and goes right to that page w/ no problem, I only have the problem when I attach it to the node from treeview. Here is what i'm working with...

    Code:
    Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
      If Node = "gohome" Then
        FilePath = "hxxp://xxx.site.com"
        OpenFileDefault hwnd, "open", FilePath, vbNullString, _
        vbNullString, 1
      End If
    End Sub
    Wasn't quite sure how I would go about fixing this problem. Didn't know if it was b/c of having "MSComctlLib" in that code or not.

    Any help is appreciated.
    Last edited by SvPir8; Apr 8th, 2007 at 08:28 PM.

  2. #2
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: TreeView Problem...

    Hi.
    You must use the API function ShellExecute.

    1st, declare the API:

    Code:
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation _
    As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    Then, on node click event:
    Code:
    Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
    dim ret&
      If Node = "gohome" Then
        FilePath = "hxxp://xxx.site.com"
        ret = ShellExecute(Me.hwnd, "OPen", FilePath, "", "", 1)
      End If
    End Sub
    Tell me if it works.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    27

    Re: TreeView Problem...

    No Sorry... It didn't help any. I already had this code entered

    Code:
    Private Declare Function OpenFileDefault Lib _
    "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _
    ByVal lpOperation As String, ByVal lpFile As String, _
    ByVal lpParameters As String, ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) As Long
    which is pretty much the same thing. I did try it though. Tried to swap out my old code for yours.

  4. #4
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: TreeView Problem...

    I've tried this code and it worked:

    Code:
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation _
    As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    
    Private Sub TreeView1_Click()
    Dim ret&
    Dim filepath
        filepath = "http://www.google.com"
        ret = ShellExecute(Me.hwnd, "OPen", filepath, "", "", 1)
    End Sub
    It must work with yours. Try making Breakpoints to see where it seek those instructions.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    27

    Re: TreeView Problem...

    Thanx... it worked. Still don't know what the problem was about the code but its all good now.


    Also I was wondering what kinda code would be involved in making it so when i opened my program the whole treeview would be collapsed? Since everytime i open it they are all opened as far as they can go...

    Tried searching but didn't find the code/help i needed
    Last edited by SvPir8; Apr 8th, 2007 at 06:55 PM.

  6. #6
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: TreeView Problem...

    Try this (it only collapse one level, but it can help in some way)

    Code:
    me.Treeview.Nodes(1).Expanded = True
    If you find someway to expand all rows tell me, ok?

  7. #7
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: TreeView Problem...

    To Collapse use .Expanded = False, to Expand .Expanded = True.
    You can use a recursive Call like this to Expand/Collapse all nodes:
    Code:
    Private Sub ExpandTree(ByVal pNode As MSComctlLib.Node, pCollapse As Boolean)
    Dim oChildNode As Node
        
        pNode.Expanded = pCollapse
        Set oChildNode = pNode.Child
        Do Until oChildNode Is Nothing
            oChildNode.Expanded = pCollapse
            ExpandTree oChildNode, pCollapse 'Recursive Call
            Set oChildNode = oChildNode.Next
        Loop
    End Sub
    Collapse all:
    Code:
    ExpandTree TreeView1.Nodes(1), False
    Expand all:
    Code:
    ExpandTree TreeView1.Nodes(1), True

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    27

    Re: TreeView Problem...

    Couldn't get either of your code to work right ...

    jcis I had the best luck w/ your code but i couldn't get it to collapse more than the 1st child. This is kinda how it looks now...

    - Main1
    | - Second
    | Third
    | - Second
    | Third
    -Main2
    | -Second
    | Third
    | -Second

    and so on...

    I wanted to make it collapse on Form_Load to look like this

    +Main1
    +Main2
    +Main3

    etc...

    I will try to work w/ the code provided since y'all were nice enough to help out.
    Maybe i'm just not seeing what I should be, I have been staring at this code for prolly a couple of hours. And I should take a break.

  9. #9
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: TreeView Problem...

    I thought your TV had only 1 Root Node. Try this:
    Code:
    Private Sub ExpandTree(pCollapse As Boolean)
    Dim lNode As Node
        
        For Each lNode In TreeView1.Nodes
            lNode.Expanded = pCollapse
        Next
        Set lNode = Nothing
    End Sub

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    27

    Re: TreeView Problem...

    lol... now i'm getting this error

    I added the ExpandTree TreeView1.Nodes(1), False line at the end of the Form_Load after it would load the TV
    Attached Images Attached Images  

  11. #11
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: TreeView Problem...

    That error message is pretty self explained, call the new Sub with 1 parameter:
    Code:
    ExpandTree False
    Last edited by jcis; Apr 8th, 2007 at 08:30 PM.

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    27

    Re: TreeView Problem...

    PERFECT! PERFECT! PERFECT!

    Thanks man. I'm still kinda new at VB and i'm not to sure about a lot of things yet w/ all the coding.

    Although I have been messing around w/ VB6 for a few years i've only begun to scratch the surface with problems

    I'm sure that i'll be using this site a lot

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