Skip to main content

DxGrid.SelectedDataItemChanged Event

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

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.1.dll

NuGet Package: DevExpress.Blazor

Declaration

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

Blazor Grid Selected Data Item Changed

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

See Also