Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

IGridSelectionChanges Interface

In This Article

Allows you to track selection changes in the Grid.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

#Declaration

C#
public interface IGridSelectionChanges

#Remarks

The Grid supports multiple row selection. The SelectedDataItems property specifies data items that correspond to the selected rows.

You can handle the SelectedDataItemsChanged event to respond to selection changes. The IGridSelectionChanges interface allows you to get data items that were added and removed from selection. To do this, cast the event handler’s parameter to this interface and use the SelectedDataItems and DeselectedDataItems properties.

The following example handles the SelectedDataItemsChanged event to display information about selection changes:

@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<NorthwindContext> NorthwindContextFactory
@implements IDisposable

<DxGrid Data="GridDataSource"
        AllowSelectRowByClick="true"
        SelectedDataItems="@SelectedDataItems"
        SelectedDataItemsChanged="OnSelectedDataItemsChanged"
        KeyFieldName="ProductId">
    <Columns>
        <DxGridDataColumn FieldName="ProductName" />
        <DxGridDataColumn FieldName="UnitPrice" />
        <DxGridDataColumn FieldName="QuantityPerUnit" />
        <DxGridDataColumn FieldName="UnitsInStock" />
    </Columns>
</DxGrid>

<br />
<div><b>Added to selection</b>: @SelectedItemsInfo</div>
<div><b>Removed from selection</b>: @DeselectedItemsInfo</div>

@code {
    IEnumerable<object> GridDataSource { get; set; }
    NorthwindContext Northwind { get; set; }
    IReadOnlyList<object> SelectedDataItems { get; set; }
    string SelectedItemsInfo { get; set; }
    string DeselectedItemsInfo { get; set; }

    protected override void OnInitialized() {
        Northwind = NorthwindContextFactory.CreateDbContext();
        GridDataSource = Northwind.Products
            .ToList();
        SelectedDataItems = GridDataSource.Skip(1).Take(2).ToList();
    }

    void OnSelectedDataItemsChanged(IReadOnlyList<object> newSelection) {
        if (newSelection is IGridSelectionChanges changes) {
            SelectedItemsInfo = string.Join(";  ", changes.SelectedDataItems
                .Cast<Product>()
                .Select(p => p.ProductName)
            );
            DeselectedItemsInfo = string.Join(";  ", changes.DeselectedDataItems
                .Cast<Product>()
                .Select(p => p.ProductName)
            );
        }
        SelectedDataItems = newSelection;
    }

    public void Dispose() {
        Northwind?.Dispose();
    }
}

See Also