Articles in this section

How to expand the particular node in .NET MAUI TreeView (SfTreeView)?

In .NET MAUI TreeView, you can expand the particular node using the ExpandNode method.

C#

Here, we expanded the specific node (Downloads) using TreeView.Loaded event.

public class Behavior : Behavior<SfTreeView>
{
    SfTreeView treeView;
    protected override void OnAttachedTo(SfTreeView bindable)
    {
        treeView = bindable;
        treeView.Loaded += OnTreeViewLoaded;
        treeView.CollapseAll();
        base.OnAttachedTo(bindable);
    }
    
    private void OnTreeViewLoaded(object sender, Syncfusion.Maui.TreeView.TreeViewLoadedEventArgs e)
    {
        int totalNodes = treeView.Nodes.Count();
        for (int i = 0; i < totalNodes; i++)
        {
            TreeViewNode node = treeView.Nodes[i];
            var content = (node.Content as Folder).FileName;
            if (content.ToString() == "Downloads")
            {
                treeView.ExpandNode(node);
            }
        }
    }
    
    protected override void OnDetachingFrom(SfTreeView bindable)
    {
        treeView.Loaded -= OnTreeViewLoaded;
        base.OnDetachingFrom(bindable);
    }
} 

Download the complete sample from GitHub

Conclusion:

I hope you enjoyed learning how to expand the particular node in .NET MAUI TreeView (SfTreeView).

You can refer to our .NET MAUI TreeView feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started with configuration specifications.

You can check out our components from the License and Downloads page for current customers. If you are new to Syncfusion®, try our 30-day free trial to check out our other controls.

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

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