Skip to main content

DxDataGrid<T>.SingleSelectedDataRowChanged Event

Occurs when a user changed selection in single selection mode.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v22.1.dll

Declaration

[Parameter]
public Action<T> SingleSelectedDataRowChanged { get; set; }

Parameters

Type Description
T

A data row.

Remarks

Important

The Data Grid was moved to maintenance support mode. No new features/capabilities will be added to this component. We recommend that you migrate to the Grid component.

Handle the SingleSelectedDataRowChanged event to track selection changes in single selection mode.

Note

Set the SelectionMode property to SingleSelectedDataRow to enable single selection mode.

<DxDataGrid Data="@DataSource"
    SelectionMode="DataGridSelectionMode.SingleSelectedDataRow"
    SingleSelectedDataRow="@SelectedProduct"
    SingleSelectedDataRowChanged="@OnSelectedProductChanged">
    ...
</DxDataGrid>

@code {
    IEnumerable<Product> DataSource;
    public Product SelectedProduct { get; set; }

    protected void OnSelectedProductChanged(Product product) {
        SelectedProduct = product;
        ...
    }

    protected override void OnInitialized() {
        ...
        SelectedProduct = DataSource.First();
    }
}

Another way to implement this task is to use the two-way synchronization.

<DxDataGrid Data="@Products" 
            @bind-SingleSelectedDataRow="@SelectedProduct" 
            KeyFieldName="@nameof(Product.ProductId)">
    @* ... *@
</DxDataGrid>

@code {
    IEnumerable<Product> Products { get; set; }
    Product selectedProduct;
    public Product SelectedProduct {
        get {
            return selectedProduct;
        }
        set {
            selectedProduct = value;
            InvokeAsync(StateHasChanged);
        }
    }
    protected override async Task OnInitializedAsync() {
        Products = await NwindDataService.GetProductsAsync();
        Categories = await NwindDataService.GetCategoriesAsync();
        SelectedProduct = Products.FirstOrDefault();
    }
}

Run Demo: Data Grid - Single Row Selection

See Also