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

Returns whether the row that corresponds to the specified data item is selected.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

#Declaration

C#
public bool IsDataItemSelected(
    object dataItem
)

#Parameters

Name Type Description
dataItem Object

The data item.

#Returns

Type Description
Boolean

true if the corresponding row is selected; otherwise, false.

#Remarks

Call the IsDataItemSelected method to identify whether the row that corresponds to the specified data item is selected. You can also call the IsRowSelected method to check whether the specified row is selected.

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

<DxGrid Data="GridDataSource"
        @bind-SelectedDataItems="@SelectedDataItems"
        KeyFieldName="ProductId"
        @ref="MyGrid">
    <Columns>
        <DxGridSelectionColumn />
        <DxGridDataColumn FieldName="ProductName" />
        <DxGridDataColumn FieldName="UnitPrice" />
        <DxGridDataColumn FieldName="QuantityPerUnit" />
        <DxGridDataColumn FieldName="UnitsInStock" />
    </Columns>
</DxGrid>

<DxButton Click="() => IsRowSelectedInfo = MyGrid.IsRowSelected(0)">
          Is First Row Selected</DxButton>
<DxButton Click="() => IsDataItemSelectedInfo = MyGrid.IsDataItemSelected(GridDataSource.First())">
           Is First Data Item Selected</DxButton>

<div><b>Is First Row Selected</b>: @IsRowSelectedInfo</div>
<div><b>Is First Data Item Selected</b>: @IsDataItemSelectedInfo</div>

@code {
    IEnumerable<object> GridDataSource { get; set; }
    NorthwindContext Northwind { get; set; }
    IReadOnlyList<object> SelectedDataItems { get; set; }
    IGrid MyGrid { get; set; }
    bool IsRowSelectedInfo { get; set; }
    bool IsDataItemSelectedInfo { 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();
    }
}

Blazor Grid Selection

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

See Also