doubt in Treeview control?

rajesh.forum

Well-known member
Joined
Sep 7, 2007
Messages
55
Programming Experience
Beginner
Hi all!!!
Im using a treeview im my form and it also working fine..I need to implement additional function in that..Normally ,all nodes of treeview ll be either collapsed or expanded.Here, the thing need to changed is ,if i click any of the parent node ,current child's should be expanded and all other parent shuold get collapsed.This is my idea.
Please give me good suggestion asap.

regards,
rajesh
 
Thread moved to Treeviews forum.

There is not doubt here, try for example AfterSelect event, target node level 0 which is root, use the ExpandAll method for the node. To collapse all other just iterate all root nodes and collapse those which are not given node.
VB.NET:
Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
    If e.Node.Level = 0 Then
        e.Node.ExpandAll()
        For Each n As TreeNode In TreeView1.Nodes
            If n IsNot e.Node Then
                n.Collapse(True)
            End If
        Next
    End If
End Sub
 
Back
Top