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.

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay