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 |
|
Remarks
The following methods allow you to manage TreeList selection:
SelectRow
(DeselectRow)- SelectRows (DeselectRows)
- SelectDataItem (DeselectDataItem)
- SelectDataItems (DeselectDataItems)
- SelectAllOnPage (DeselectAllOnPage)
- SelectAllAsync (DeselectAllAsync)
- ClearSelection
Pass a row’s visible index to the SelectRow
method to select that row. The method’s behavior depends on the SelectionMode property value:
- In multiple selection mode, the method keeps the previously selected rows and adds the specified row to selection. To access data items that correspond to selected rows, implement two-way binding for the SelectedDataItems property or handle the SelectedDataItemsChanged event.
- In single selection mode, the method changes selection to the specified row. To access a data item that corresponds to the selected row, implement two-way binding for the SelectedDataItem property or handle the SelectedDataItemChanged event.
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 passfalse
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();
}
}
For more information about selection in the TreeList component, refer to the following topic: Selection and Focus in Blazor TreeList.