Expand/Collapse Items

RadTreeView exposes several useful methods which can be utilized in order to control the states of its items. You can use the following methods when trying to change the state of an individual item:

  • void Expand(object item): Expands a specific item from the source collection
  • void Collapse(object item): Collapses a specific item from the source collection

The following code snippets show how to expand/collapse a specific item from the code-behind of the page where the control is defined:

private void ExpandItem2(object sender, EventArgs e)
{
    var item2 = (treeView.ItemsSource as IList<Item>)[1];
    treeView.Expand(item2);
}      
private void CollapseItem2(object sender, EventArgs e)
{
    var item2 = (treeView.ItemsSource as IList<Item>)[1];
    treeView.Collapse(item2);
}

Where Item is the business object used in the TreeView ItemsSource collection.

If you would like to collapse/expand all items within the source collection, you can utilize the following methods:

  • void ExpandAll(): Expands all items from the source collection
  • void CollapseAll(): Collapses all items from the source collection
private void ExpandAll(object sender, EventArgs e)
{
    treeView.ExpandAll();
}
private void CollapseAll(object sender, EventArgs e)
{
    treeView.CollapseAll();
}

You can check a runnable demo in the Features section of the RadTreeView component in the SDK Samples Browser application(can be found in the Examples folder of your local Telerik UI for Xamarin installation)

See Also

In this article
Not finding the help you need? Improve this article