Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

DxTreeView.GetNodeExpanded(Func<ITreeViewNodeInfo, Boolean>) Method

Returns whether the specified node is expanded.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

#Declaration

C#
public bool GetNodeExpanded(
    Func<ITreeViewNodeInfo, bool> predicate
)

#Parameters

Name Type Description
predicate Func<ITreeViewNodeInfo, Boolean>

A method delegate that specifies a particular node.

#Returns

Type Description
Boolean

true, if the node is expanded; false, if the node is collapsed.

#Remarks

Razor
<DxTreeView @ref="@treeView" 
            AllowSelectNodes="true" 
            BeforeCollapse="@BeforeExpandCollapse" 
            BeforeExpand="@BeforeExpandCollapse" 
            SelectionChanged="@SelectionChanged">
    @* ... *@
</DxTreeView>

@code {
    DxTreeView treeView;

    protected void SelectionChanged(TreeViewNodeEventArgs e) {
        if (e.NodeInfo.IsLeaf && e.NodeInfo.Level == 0) {
            treeView.CollapseAll();
        }
        else if (!e.NodeInfo.IsLeaf) {
            Func<ITreeViewNodeInfo, bool> nodePredicate = n => string.Equals(n.Text, e.NodeInfo.Text);

            bool nodeExpanded = treeView.GetNodeExpanded(nodePredicate);
            if (!nodeExpanded) {
                treeView.CollapseAll();
            }
            treeView.SetNodeExpanded(nodePredicate, !nodeExpanded);
        }
    }

    protected void BeforeExpandCollapse(TreeViewNodeCancelEventArgs e) {
        e.Cancel = true;
    }
}

Note

This method is not in effect if Load Child Nodes on Demand mode is enabled, and the specified node is not loaded yet.

View Example: Demo Navigation Menu

See Also