Skip to main content

DxGrid.SelectRow(Int32, Boolean) Method

Selects or deselects a row with the specified visible index.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v23.2.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

The following methods allow you to manage Grid selection:

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:

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 GridDevExtremeDataSource loads data asynchronously in small portions (instead of the entire dataset). Before you call the SelectRow method, call the WaitForRemoteSourceRowLoadAsync(Int32) method to ensure that the specified data row is loaded.

To deselect a row by its visible index, do any of the following:

  • Call the DeselectRow(Int32) method.
  • Call the SelectRow method and pass false as the second parameter.

Tip

When you call SelectRow or DeselectRow method, the component sends a callback and redraws the grid. If you select or deselect several rows, for instance, in cycle, it can reduce overall performance. We recommend that you call the SelectRows or DeselectRows method instead to avoid unnecessary callbacks and redraws.

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();
    }
}

Blazor Grid Select and Deselect Row

Run Demo: Data Grid - Selection API

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

See Also