Sven Glöckner
Posted on February 26, 2020
Today, I want to refresh the treeview items in a DevExpress Blazor DxTreeView.
Imagine you edited one of the node's items and want to refresh the whole tree without loosing the selected node.
My DxTreeView
<DxTreeView @ref="@_treeView" AllowSelectNodes="true" SelectionChanged=@(async e => await SelectChildNodeAsync(e))
Data=@TreeViewItems
NameExpression="@(dataItem => ((Model.TreeViewItem)dataItem).Id.ToString())"
TextExpression="@(dataItem => ((Model.TreeViewItem)dataItem).Name)"
ChildrenExpression="@(dataItem => ((Model.TreeViewItem)dataItem).Items)">
</DxTreeView>
After editing finished, you could programmatically refresh the treeview's datasource, expand and select the current node with the help of the API:
TreeViewItems = await DataAccess.GetTreeViewData();
await InvokeAsync(StateHasChanged);
_treeView.ExpandToNode(nodeInfo => nodeInfo.Name == DetailItem.Id.ToString());
_treeView.SelectNode(nodeInfo => nodeInfo.Name == DetailItem.Id.ToString());
💖 💪 🙅 🚩
Sven Glöckner
Posted on February 26, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.