Please help me with treeview

When I click a node I want to the other nodes(including their childnode are closed - not expand) but I don't know how to do this.

Please give me some suggestion !

Thanks a lot !




Answer this question

Please help me with treeview

  • amidar

    I want to the same level nodes are closed.



  • JaganG

    What do you want the other nodes to do From what level ( that is, below the selected node, or across the entire tree )



  • Yew Thean Hoo

    Please be more clear.

    You have a tree with nodes which in turn have child nodes. Now when you click a node, what exactly should happen

    Anyway check the code below. I have TreeView which is like this:

    Root

    C1

    c11

    c22

    C2

    c21

    c22

    If you have multiple levels and get the parent node of the selected node and collapse all the nodes under the parent of the selected node.Anything more needed, please feel free to contact me.

    Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
    'to close all the nodes under the selected node
    If Not IsNothing(e.Node.Parent) Then
    ' to close all the nodes under the selected node
    If e.Node.IsExpanded Then e.Node.Collapse(True)
    End If

    ' this is to collpase the all the nodes in the same level
    If Not IsNothing(e.Node.Parent) Then
    If TreeView1.Nodes.Count > 0 Then
    Dim iLoop As Integer
    For iLoop = 0 To TreeView1.Nodes.Count - 1
    If TreeView1.Nodes(iLoop).IsExpanded Then
    TreeView1.Nodes(iLoop).Collapse(True)
    End If
    Next

    End If
    End If


    End Sub


  • IvanLieb

    Thanks Ashraf Hameeda T !



  • Please help me with treeview