I have the following setup
<SfTreeView ID="treeview" @ref="elementTree" TValue="LearningElement" FullRowSelect="true" AllowMultiSelection="true">
<TreeViewEvents TValue="LearningElement" NodeSelected="TreeItemSelected"></TreeViewEvents>
<TreeViewFieldsSettings TValue="LearningElement" Id="NodePath"
Text="Name"
DataSource="@Elements"
Child="@ElementChildren"
Selected="Selected"
Expanded="Expanded"></TreeViewFieldsSettings>
<TreeViewTemplates>
<NodeTemplate>
@{
var element = ((context as LearningElement));
<div class="small">@element.Name</div>
}
</NodeTemplate>
</TreeViewTemplates>
</SfTreeView>
protected void TreeItemSelected(NodeSelectEventArgs args)
{
if (args.NodeData.Id != null)
{
// Do Something
}
}
internal void SetSelectedItem(string nodePath)
{
try
{
if (elementTree != null)
{
elementTree.SelectedNodes = new string[] { nodePath };
InvokeAsync(() => StateHasChanged());
}
}
catch (Exception ex)
{
}
}
The problem is as follows:
- Initial Load - tree loads up fine.
- User clicks a button which calls SetSelectedItem() to select a node in the tree (Item #1) . The item is highlighted, and TreeItemSelected() fires.
- User clicks on a node in the tree. TreeItemSelected() fires.
- Now user clicks on the button again. This calls SetSelectedItem()but this time, the item in the tree is NOT highlighted, and TreeItemSelected() does NOT fire.
Attached is the screen shot for the steps. Any thoughts on this?
Attachment:
Selecting_Tree_Nodes_Programmatically_6fb1cfb.zip