Skip to main content
All docs
V24.2

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

DxTreeList.SelectRows(IEnumerable<Int32>, Boolean) Method

Selects or deselects rows with the specified visible indexes.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

#Declaration

C#
public void SelectRows(
    IEnumerable<int> visibleIndexes,
    bool selected = true
)

#Parameters

Name Type Description
visibleIndexes IEnumerable<Int32>

Specifies a collection of visible indexes.

#Optional Parameters

Name Type Default Description
selected Boolean True

true to select rows; false to deselect rows.

#Remarks

The following methods allow you to manage TreeList selection:

When the SelectionMode property is set to Multiple, the SelectRows method allows you to add multiple rows to the current selection. Call this method and pass a collection of visible indexes as the parameter.

If you call the SelectRows method in Single mode, it clears selection and selects only one row with the last specified index.

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 DeselectRows and SelectRows methods.

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

You can deselect rows with specified visible indexes in the following ways:

  • Call the DeselectRows method.
  • Call the SelectRows method and pass false as the second parameter.

To access data items that correspond to selected rows, implement two-way binding for the SelectedDataItems property or handle the SelectedDataItemsChanged event.

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 rows whose indexes are between 3 and 5:

@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.SelectRows(RowIndexes)" CssClass="my-button" Text="Select Rows 4-6"/>
<DxButton Click="() => MyTreeList.DeselectRows(RowIndexes)" CssClass="my-button" Text="Deselect Rows 4-6"/>

@code {
    List<EmployeeTask> TreeListData { get; set; }
    IReadOnlyList<object> SelectedDataItems { get; set; }
    ITreeList MyTreeList { get; set; }
    int[] RowIndexes { get; set; } = new int[] { 3, 4, 5 };

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

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

See Also