Skip to main content
All docs
V26.1
  • DxGrid.IsRowSelected(Int32) Method

    Returns whether the specified row is selected.

    Namespace: DevExpress.Blazor

    Assembly: DevExpress.Blazor.Grid.v26.1.dll

    NuGet Package: DevExpress.Blazor

    Declaration

    public bool IsRowSelected(
        int visibleIndex
    )

    Parameters

    Name Type Description
    visibleIndex Int32

    The row’s visible index.

    Returns

    Type Description
    Boolean

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

    Remarks

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

    Note

    The Grid bound to an Instant Feedback Data Source or GridDevExtremeDataSource loads data asynchronously in small portions (instead of the entire dataset). Before you call the IsRowSelected method, call the WaitForRemoteSourceRowLoadAsync(Int32) method to ensure that the specified data row is loaded.

    @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 additional information about selection in the Grid component, refer to the following topic: Selection and Focus in Blazor Grid.

    See Also