Articles in this section
Category / Section

How to Expand Child Nodes Selected Programatically in WF TreeViewAdv?

1 min read

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



Conclusion

I hope you enjoyed learning about how to expand selected child nodes  programatically in WinForms TreeViewAdv.

You can refer to our WinForms TreeView page to know about its other groundbreaking feature representations. You can also explore our WinFormsTreeViewAdv Documentation to understand how to manipulate data.

For current customers you can check out on our Winforms components from the License and Download page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms TreeViewAdv  and other WinForms components.

If you have any queries or require clarifications, please let us know in the comment section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!


Figure 2: After expanding the TreeNodeAdv on selection 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied