How to select a node when not using multiselect
Hi,
I am working from this example:
Node Selection in Blazor TreeView Component | Syncfusion
using the example: "Select individual node programmatically"
Trying to select a newly added node programmatically after adding it.
What am I doing:
- Refreshing the treeview after adding the node data to the DataSource
- Using SelectedNodes array
But this only seems to work when MultiSelect is true -
How can I make this work in a Treeview with MultiSelect = false ?
I have also tried the example with setting "Selected" in the node - but that also doesn't work
Peter
Hi Peter,
Greetings from Syncfusion support.
Based on the provided details, we understand that you expect to select a tree item when it is dynamically added, with the AllowMultiSelection set to false. In response to your request, we have prepared and included the sample.
Here, we have dynamically changed the TreeView SelectedNodes property with the multiple selection feature is disabled. Please refer to the code snippets, sample and output screenshots provided below for reference.
Sample : https://blazorplayground.syncfusion.com/rNreDFiOpKnsWKEU
|
@using Syncfusion.Blazor.Navigations <SfButton OnClick="AddNodes">Add Node</SfButton> <br/> <SfTreeView TValue="MailItem" AllowMultiSelection=false @bind-SelectedNodes="SelectedNodes"> <TreeViewFieldsSettings TValue="MailItem" Id="Id" DataSource="@MyFolder" Text="FolderName" ParentID="ParentId" HasChildren="HasSubFolders" Expanded="Expanded" Selected="Selected"></TreeViewFieldsSettings> </SfTreeView> @code{ int index = 100; public string[] SelectedNodes = new string[] { "8"}; // Add new node and select it public async Task AddNodes() { SelectedNodes = new string[] { }; MyFolder.Add(new MailItem { Id = "new_tree_item"+this.index.ToString(), FolderName = "NewItem"+this.index.ToString(), ParentId = "6", }); SelectedNodes = new string[] { "new_tree_item"+this.index.ToString() }; this.index = this.index + 1; } public class MailItem { public string? Id { get; set; } public string? ParentId { get; set; } public string? FolderName { get; set; } public bool Expanded { get; set; } public bool HasSubFolders { get; set; } public bool Selected { get; set; } } … } |
Output screenshots:
|
Selected nodes with initial rendering |
Dynamically added nodes will be selected |
|
|
|
Refer to the shared details and sample on your end. Please get back to us if you need any further assistance.
Regards,
Leo Lavanya Dhanaraj
- 1 Reply
- 2 Participants
-
PR Peter Rasmussen
- Aug 15, 2025 08:16 AM UTC
- Aug 19, 2025 12:49 PM UTC