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.DeselectDataItem(Object) Method

Deselects a row that corresponds to the specified data item.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

#Declaration

C#
public void DeselectDataItem(
    object dataItem
)

#Parameters

Name Type Description
dataItem Object

The data item.

#Remarks

The following methods allow you to manage Grid selection:

Call the DeselectDataItem method to remove a specified data item and the corresponding row from selection. To select a row and its data item, call the SelectDataItem method.

To access selected data items, do one of the following:

The following example selects and deselects a row that corresponds to the first data item:

@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.SelectDataItem(GridDataSource.First())">Select First Data Item</DxButton>
<DxButton Click="() => MyGrid.DeselectDataItem(GridDataSource.First())">Deselect First Data Item</DxButton>

@code {
    IEnumerable<object> GridDataSource { get; set; }
    NorthwindContext Northwind { get; set; }
    IReadOnlyList<object> SelectedDataItems { get; set; }
    IGrid MyGrid { get; set; }

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

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

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