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

DxGrid.SelectedDataItemChanged Event

In single selection mode, fires when another Grid row is selected.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

#Declaration

C#
[Parameter]
public EventCallback<object> SelectedDataItemChanged { get; set; }

#Parameters

Type Description
Object

The data item that corresponds to the newly selected row.

#Remarks

The SelectedDataItemChanged event fires each time the SelectedDataItem property changes. This property specifies the data item that corresponds to the selected Grid row in single selection mode.

The event is handled automatically when you use two-way data binding for the SelectedDataItem property (@bind-SelectedDataItem). You can also implement a custom event handler to respond to selection changes.

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

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

<DxGrid Data="GridDataSource"
        AllowSelectRowByClick="true"
        SelectionMode="GridSelectionMode.Single"
        SelectedDataItem="@SelectedDataItem"
        SelectedDataItemChanged="OnSelectedDataItemChanged"
        KeyFieldName="ProductId">
    <Columns>
        <DxGridDataColumn FieldName="ProductName" />
        <DxGridDataColumn FieldName="UnitPrice" />
        <DxGridDataColumn FieldName="QuantityPerUnit" />
        <DxGridDataColumn FieldName="UnitsInStock" />
    </Columns>
</DxGrid>

<br />
<div>@SelectionChangesInfo</div>

@code {
    IEnumerable<object> GridDataSource { get; set; }
    NorthwindContext Northwind { get; set; }
    object SelectedDataItem { get; set; }
    string SelectionChangesInfo { get; set; }

    protected override void OnInitialized() {
        Northwind = NorthwindContextFactory.CreateDbContext();
        GridDataSource = Northwind.Products
            .ToList();
        SelectedDataItem = GridDataSource.FirstOrDefault();
    }

    void OnSelectedDataItemChanged(object newSelection) {
        SelectionChangesInfo = "You selected '" + (newSelection as Product).ProductName +
            "' and deselected '" + (SelectedDataItem as Product).ProductName + "'";
        SelectedDataItem = newSelection;
    }

    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.

See Also