DxGrid.SelectRow(Int32, Boolean) Method
Selects or deselects a row with the specified visible index.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v22.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
Call the SelectRow
method and pass a row’s visible index 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
When the Grid calculates visible indexes, it counts data rows and group rows. However, only data rows can be selected.
To deselect a row by its visible index, do any of the following:
- Call the DeselectRow(Int32) method.
- Call the
SelectRow
method and passfalse
as the second parameter.
The following example selects and deselects a row whose visible index is 0:
@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<NorthwindContext> NorthwindContextFactory
@implements IDisposable
<DxGrid Data="GridDataSource"
AllowSelectRowByClick="true"
@bind-SelectedDataItems="@SelectedDataItems"
KeyFieldName="ProductId"
@ref="MyGrid">
<Columns>
<DxGridDataColumn FieldName="ProductName" />
<DxGridDataColumn FieldName="UnitPrice" />
<DxGridDataColumn FieldName="QuantityPerUnit" />
<DxGridDataColumn FieldName="UnitsInStock" />
</Columns>
</DxGrid>
<br/>
<DxButton Click="() => MyGrid.SelectRow(0)">Select First Row</DxButton>
<DxButton Click="() => MyGrid.DeselectRow(0)">Deselect First Row</DxButton>
@code {
IEnumerable<object> GridDataSource { get; set; }
NorthwindContext Northwind { get; set; }
IReadOnlyList<object> SelectedDataItems { get; set; }
IGrid MyGrid { get; set; }
protected override void OnInitialized() {
Northwind = NorthwindContextFactory.CreateDbContext();
GridDataSource = Northwind.Products
.ToList();
SelectedDataItems = GridDataSource.Skip(1).Take(2).ToList();
}
public void Dispose() {
Northwind?.Dispose();
}
}
You can also call the following methods to manage selection:
- SelectRows | DeselectRows
- SelectDataItem | DeselectDataItem
- SelectDataItems | DeselectDataItems
- SelectAllOnPage | DeselectAllOnPage
- ClearSelection
Note
When you use a GridDevExtremeDataSource, do not call the SelectRow
method for a row that is outside the visible display range. The GridDevExtremeDataSource
loads only data required to display the current page. If you have a reference to the corresponding data item, you can call the SelectDataItem(Object, Boolean) method.