Skip to main content

DevExpress v24.1 Update — Your Feedback Matters

Our What's New in v24.1 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.SelectAllAsync(Boolean) Method

Selects or deselects all rows in the grid.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.1.dll

NuGet Package: DevExpress.Blazor

#Declaration

C#
public Task SelectAllAsync(
    bool selected = true
)

#Optional Parameters

Name Type Default Description
selected Boolean True

true to select rows; false to deselect rows.

#Returns

Type Description
Task

The task that is completed when all rows are selected.

#Remarks

The following methods allow you to manage Grid selection:

Call the SelectAllAsync method to select or deselect all rows in the grid. This method does not affect the selection state of the rows hidden by a filter.

If you call the SelectAllAsync(true) method when the SelectionMode property is set to Single, the method clears selection and selects only the last grid row.

To deselect all rows, call the SelectAllAsync(false) or DeselectAllAsync() method.

To access data items that correspond to selected rows, implement two-way binding for the SelectedDataItems property or handle the SelectedDataItemsChanged event.

Razor
<DxGrid Data="@Products" @ref="Grid" KeyFieldName="ProductId" 
        AllowSelectRowByClick="true" @bind-SelectedDataItems="@SelectedDataItems">
    <Columns>
        <DxGridDataColumn FieldName="ProductName" />
        <DxGridDataColumn FieldName="Category"/>
        <DxGridDataColumn FieldName="UnitPrice" DisplayFormat="c" />
        <DxGridDataColumn FieldName="UnitsInStock" />
    </Columns>
</DxGrid>
<DxButton Click="SelectAll">Select All Rows</DxButton>
<DxButton Click="DeselectAll">Deselect All Rows</DxButton>

@code {
    IEnumerable<Product> Products { get; set; }
    IReadOnlyList<object> SelectedDataItems { get; set; }
    IGrid Grid { get; set; }

    protected override async Task OnInitializedAsync() {
        Products = await NwindDataService.GetProductsAsync();
    }
    async Task SelectAll(MouseEventArgs args) {
        await Grid.SelectAllAsync();
    }
    async Task DeselectAll(MouseEventArgs args) {
        await Grid.DeselectAllAsync();
    }
}

Run Demo: Data Grid - Selection API

#Large Data Limitation

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

See Also