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
public void SelectRows(
IEnumerable<int> visibleIndexes,
bool selected = true
)
#Parameters
Name | Type | Description |
---|---|---|
visible |
IEnumerable<Int32> | Specifies a collection of visible indexes. |
#Optional Parameters
Name | Type | Default | Description |
---|---|---|---|
selected | Boolean | True |
|
#Remarks
The following methods allow you to manage TreeList selection:
- SelectRow (DeselectRow)
SelectRows
(DeselectRows)- SelectDataItem (DeselectDataItem)
- SelectDataItems (DeselectDataItems)
- SelectAllOnPage (DeselectAllOnPage)
- SelectAllAsync (DeselectAllAsync)
- ClearSelection
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 DeselectSelect
methods.
When the TreeSelect
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 passfalse
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 SelectSelect
or Deselect
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.