Results 1 to 5 of 5

Thread: How to expand TreeView nodes?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    2,012

    How to expand TreeView nodes?

    I know how to get the full path of a treeview node, but how do I do the reverse? ie. If I have a path to a node stored in a variable, how do I expand all the nodes in that path? Thanks...

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: How to expand TreeView nodes?

    if you have a reference to a TreeNode object in a variable, just call its .EnsureVisible method, and it will scroll and expand nodes as needed to make sure the given node is now visible in the control...

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    2,012

    Re: How to expand TreeView nodes?

    What if I dont have a reference to the node? I just know its .FullPath value. Do I have to iterate through the tree & match each node name to each folder name in the path?

  4. #4
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: How to expand TreeView nodes?

    Quote Originally Posted by nbrege
    I know how to get the full path of a treeview node, but how do I do the reverse? ie. If I have a path to a node stored in a variable, how do I expand all the nodes in that path? Thanks...
    Hi,

    You can use the Treeview expand method.

    The following code example toggles the selected node when a button is clicked. If the selected node is collapsed, it is expanded, if it is expanded by calling the Expand method, it is collapsed by calling the Collapse method. This example requires that you have a Form with a TreeView control that has at least one TreeNode with at least one child TreeNode.

    Code:
    Private Sub button1_Click(sender As Object, _
      e As System.EventArgs) Handles button1.Click
       If treeView1.SelectedNode.IsExpanded Then
          treeView1.SelectedNode.Collapse()
          MessageBox.Show(treeView1.SelectedNode.Text & _ 
            " tree node collapsed.")
       Else
          treeView1.SelectedNode.Expand()
          MessageBox.Show(treeView1.SelectedNode.Text & _
            " tree node expanded.")
       End If
    End Sub
    Hope it helps,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  5. #5
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: How to expand TreeView nodes?

    I don't know any specific way to reference a treenode via its fullpath property without looping the entire set of nodes in the treeview and doing a comparison...

    I suppose you could parse out the full path into each node and select each node that is parsed out one by one until you get to the desired node.

    Another option would be to make the "key" property of the treenode the fullpath of the node. This way you could use the .Find() method of the nodes collection and pass the fullpath, which would inturn find the node whose key matches.

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