Skip to main content
All docs
V24.1

DxTreeList.SelectRow(Int32, Boolean) Method

Selects or deselects a row with the specified visible index.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.1.dll

NuGet Package: DevExpress.Blazor

Declaration

public void SelectRow(
    int visibleIndex,
    bool selected = true
)

Parameters

Name Type Description
visibleIndex Int32

The row’s visible index.

Optional Parameters

Name Type Default Description
selected Boolean True

true to select the row; false to deselect the row.

Remarks

The following methods allow you to manage TreeList selection:

Pass a row’s visible index to the SelectRow method to select that row. The method’s behavior depends on the SelectionMode property value:

Note

Rows that are filtered out and child rows of collapsed items do not have visible indexes. You cannot change the selection state of such rows with DeselectRow and SelectRow methods.

When the TreeList is bound to the GridDevExtremeDataSource or loads data on demand, call the WaitForRemoteSourceRowLoadAsync(Int32) method before you execute the SelectRow method to ensure that the specified data row is loaded.

You can deselect a row with the specified visible index in the following ways:

  • Call the DeselectRow(Int32) method.
  • Call the SelectRow method and pass false as the second parameter.

Tip

When you call the SelectRow or DeselectRow method, the component sends a callback and redraws the TreeList. If you select or deselect multiple rows, for instance, in a cycle, it can reduce overall performance. Call the SelectRows or DeselectRows method instead to avoid unnecessary callbacks and redraws.

The following example selects and deselects the first row:

@inject EmployeeTaskService EmployeeTaskService

<style>
    .my-button {
        width: 200px;
    }
</style>

<DxTreeList @ref="MyTreeList"
            Data="TreeListData"
            KeyFieldName="Id"
            ParentKeyFieldName="ParentId"
            AllowSelectRowByClick="true"
            @bind-SelectedDataItems="@SelectedDataItems">
    <Columns>
        <DxTreeListDataColumn FieldName="Name" Caption="Task" />
        <DxTreeListDataColumn FieldName="EmployeeName" />
        <DxTreeListDataColumn FieldName="StartDate" />
        <DxTreeListDataColumn FieldName="DueDate" />
    </Columns>
</DxTreeList>

<DxButton Click="() => MyTreeList.SelectRow(0)" CssClass="my-button" Text="Select First Row" />
<DxButton Click="() => MyTreeList.DeselectRow(0)" CssClass="my-button" Text="Deselect First Row" />

@code {
    List<EmployeeTask> TreeListData { get; set; }
    IReadOnlyList<object> SelectedDataItems { get; set; }
    ITreeList MyTreeList { get; set; }

    protected override void OnInitialized() {
        TreeListData = EmployeeTaskService.GenerateData();
    }
}

Blazor TreeList Select and Deselect Row

For more information about selection in the TreeList component, refer to the following topic: Selection and Focus in Blazor TreeList.

See Also