Skip to main content

DxGrid.IsDataItemSelected(Object) Method

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

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.1.dll

NuGet Package: DevExpress.Blazor

Declaration

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