Programmatically Select, Expand and Close nodes of the Blazor Treeview

Hi,

Is there a way to programmatically Select, Expand and Close nodes of the Blazor Treeview? I am using the Treeview as a left hand menu and need to synchronise it with selections made in a details panel.

Thanks in advance.

Cliff Harrison.



1 Reply

IL Indhumathy Loganathan Syncfusion Team August 17, 2022 10:53 AM UTC

Hi Cliff,


Greetings from Syncfusion support.


Yes, you can perform select, expand and collapse operations in the TreeView component by using the following API properties and method.


Operation

API

To select the TreeView node

SelectedNodes - https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Navigations.SfTreeView-1.html#Syncfusion_Blazor_Navigations_SfTreeView_1_SelectedNodes

 

To expand the TreeView node

ExpandedNodes - https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Navigations.SfTreeView-1.html#Syncfusion_Blazor_Navigations_SfTreeView_1_ExpandedNodes

 

To collapse the TreeView node

CollapseAllAsync - https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Navigations.SfTreeView-1.html#Syncfusion_Blazor_Navigations_SfTreeView_1_CollapseAllAsync_System_String___


For your reference, we have prepared a simple sample to perform all the above operations in a button click. Check the below code snippet.


  public void expand()

  {

      //Expands the mentioned node.

      ExpandedNodes = new String[] { "1" };

  }

  public void select()

  {

      //Selects the mentioned node.

      SelectedNodes = new String[] { "2" };

  }

  public void collapse()

  {

      //Collapses the mentioned node.

      tree.CollapseAllAsync(new String[] { "1"});

  }


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/TreeViewSample1014030824


Please check the attached sample and get back to us if you need any further assistance.


Note: If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Regards,

Indhumathy L


Loader.
Up arrow icon