DEV Community

Sven Glöckner
Sven Glöckner

Posted on

3 2

Refreshing DxTreeView items and keep selection

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());

See also the issue on GitHub.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more