DxGrid.DeselectRow(Int32) Method
Deselects a row with the specified visible index.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v24.2.dll
NuGet Package: DevExpress.Blazor
#Declaration
public void DeselectRow(
int visibleIndex
)
#Parameters
Name | Type | Description |
---|---|---|
visible |
Int32 | The row’s visible index. |
#Remarks
The following methods allow you to manage Grid selection:
- SelectRow (
DeselectRow
) - SelectRows (DeselectRows)
- SelectDataItem (DeselectDataItem)
- SelectDataItems (DeselectDataItems)
- SelectAllOnPage (DeselectAllOnPage)
- SelectAllAsync (DeselectAllAsync)
- ClearSelection
Call the DeselectRow
method and pass a row’s visible index to remove that row from selection. To select a row by its visible index, call the SelectRow method.
Note
When the Grid calculates visible indexes, it counts data rows and group rows. However, only data rows can be selected.
The Grid bound to an Instant Feedback Data Source or GridDeselect
method, call the Wait
To access data items that correspond to selected rows, do one of the following:
- In multiple selection mode, implement two-way binding for the SelectedDataItems property or handle the SelectedDataItemsChanged event.
- In single selection mode, implement two-way binding for the SelectedDataItem property or handle the SelectedDataItemChanged event.
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();
}
}
For more information about selection in the Grid component, refer to the following topic: Selection and Focus in Blazor Grid.