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.SelectNode(Func<ITreeViewNodeInfo, Boolean>) Method

Selects the specified node.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

#Declaration

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

#Parameters

Name Type Description
predicate Func<ITreeViewNodeInfo, Boolean>

A method delegate that specifies a particular node.

#Remarks

When the AllowSelectNodes property is set to true, the DxTreeView component allows node selection. Use the SelectNode method to select a node programmatically. If none of the nodes meet the specified condition, the component does not clear selection. Call the ClearSelection() method to deselect nodes.

The following example selects the Lanthanides node and expands all its parent nodes:

Razor
<button type="button" @onclick="@(() => SelectNode("Lanthanides"))">Select Lanthanides</button>

<DxTreeView @ref="@SampleTreeView" AllowSelectNodes="true">
    <Nodes>
        <DxTreeViewNode Text="Metals">
            <Nodes>
                <DxTreeViewNode Text="Alkali metals" />
                <DxTreeViewNode Text="Alkaline earth metals" />
                <DxTreeViewNode Text="Inner transition elements">
                    <Nodes>
                        <DxTreeViewNode Text="Lanthanides" />
                        <DxTreeViewNode Text="Actinides" />
                    </Nodes>
                </DxTreeViewNode>
                <DxTreeViewNode Text="Transition elements" />
                <DxTreeViewNode Text="Other metals" />
            </Nodes>
        </DxTreeViewNode>
        <DxTreeViewNode Text="Metalloids" />
        <DxTreeViewNode Text="Nonmetals" />
    </Nodes>
</DxTreeView>    

@code  {
    DxTreeView SampleTreeView;

    void SelectNode(string text) {
        SampleTreeView.SelectNode((n) => n.Text == text);
        SampleTreeView.ExpandToNode((n) => n.Text == text);
    }
}

Note

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

See Also