)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to expand all the child nodes of the selected TreeNodeAdv programatically in WinForms TreeViewAdv?

Platform: WinForms |
Control: TreeViewAdv |
Published Date: September 8, 2015 |
Last Revised Date: February 4, 2020

Expand the child nodes of selected TreeNodeAdv

In the TreeViewAdv, TreeNodeAdv can be expanded by using the Expand and ExpandAll functions.

1. Expand: This function helps to expand a particular TreeNodeAdv.

2. ExpandAll: This function helps to expand the node and all its sub nodes.

 

To expand all the child nodes under the selected TreeNodeAdv programmatically, follow the steps:

1. Handle AfterSelect event that is triggered when the TreeNodeAdv is selected.

2. Iterate the TreeNodeAdvCollection and invoke the Expand function.

C#

//The event is raised on TreeNodeAdv selection.
private void treeViewAdv1_AfterSelect(object sender, EventArgs e)
{
    string selectedNode = this.treeViewAdv1.SelectedNode.Text;
    if (this.treeViewAdv1.Nodes.Count > 0)
    {
        foreach (TreeNodeAdv treeNode in Collect(this.treeViewAdv1.Nodes))
        {
            if (selectedNode == treeNode.Text)
            {
                //Expands all the TreeNodeAdv.
                treeNode.ExpandAll();
                break;
            }
        }
    }
}

VB

'The event is raised on TreeNodeAdv selection.
Private Sub treeViewAdv1_AfterSelect(ByVal sender As Object, ByVal e As EventArgs) Handles treeViewAdv1.AfterSelect
   Dim selectedNode As String = Me.treeViewAdv1.SelectedNode.Text
   If Me.treeViewAdv1.Nodes.Count > 0 Then
      For Each treeNode As TreeNodeAdv In Me.treeViewAdv1.Nodes
           If selectedNode = treeNode.Text Then
               'Expands all the TreeNodeAdv.
               treeNode.ExpandAll()
               Exit For
           End If
      Next treeNode
   End If
End Sub

 

Shows before expanding the TreeNodeAdv

Figure 1: Before expanding the TreeNodeAdv

Shows After expanding the TreeNodeAdv on selection

Figure 2: After expanding the TreeNodeAdv on selection 

Samples:

C#: TreeViewAdv_AfterSelect_C#

VB: TreeViewAdv_AfterSelect_VB

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon