Skip to main content

DxGrid.DeselectRows(IEnumerable<Int32>) Method

Deselects rows with the specified visible indexes.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

Declaration

public void DeselectRows(
    IEnumerable<int> visibleIndexes
)

Parameters

Name Type Description
visibleIndexes IEnumerable<Int32>

Specifies a collection of row visible indexes.

Remarks

The following methods allow you to manage Grid selection:

Call the DeselectRows method and pass a collection of row visible indexes to remove these rows from selection. To select rows by their visible indexes, call the SelectRows 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 GridDevExtremeDataSource loads data asynchronously in small portions (instead of the entire dataset). Before you call the DeselectRows method, call the WaitForRemoteSourceRowLoadAsync(Int32) method to ensure that the specified data row is loaded.

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 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 rows whose indexes are between 3 and 5:

@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.SelectRows(RowIndexes)">Select Rows 4-6</DxButton>
<DxButton Click="() => MyGrid.DeselectRows(RowIndexes)">Deselect Rows 4-6</DxButton>

@code {
    IEnumerable<object> GridDataSource { get; set; }
    NorthwindContext Northwind { get; set; }
    IReadOnlyList<object> SelectedDataItems { get; set; }
    IGrid MyGrid { get; set; }
    int[] RowIndexes { get; set; } = new int[] { 3, 4, 5 };

    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 Rows

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