Skip to main content

DxGrid.GetFocusedRowIndex() Method

Returns the visible index of the focused row.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

Declaration

public int GetFocusedRowIndex()

Returns

Type Description
Int32

If a data row is focused, the method returns this row’s visible index. The method returns -1 if a new row is focused or the Grid displays no rows.

Remarks

When the FocusedRowEnabled property is set to true, the grid displays the focused row. Call the GetFocusedRowIndex method to get the index of the currently focused row. To focus a row with the specified visible index, call the SetFocusedRowIndex(Int32) method.

When the focused row changes, the grid invokes the FocusedRowChanged event.

You can use the GetFocusedDataItem() method to get the data item bound to the focused row.

In the following code snippet, the GetFocusedRowIndex() and SetFocusedRowIndex(Int32) methods are used to move focus between rows.

<div class="d-flex py-2">
    <DxButton Text="Previous" Click="MoveFocusBackward" Enabled="PreviousEnabled" />
    <DxButton Text="Next" Click="MoveFocusForward" Enabled="NextEnabled" CssClass="mx-2" />
</div>
<DxGrid @ref="Grid" Data="Data" PageSize="6"
        FocusedRowEnabled="true" FocusedRowChanged="Grid_FocusedRowChanged">
    <Columns>
        <DxGridDataColumn FieldName="ContactName" />
        <DxGridDataColumn FieldName="CompanyName" />
        <DxGridDataColumn FieldName="City" />
        <DxGridDataColumn FieldName="Country" />
    </Columns>
</DxGrid>
@code {
    bool PreviousEnabled;
    bool NextEnabled;
    IGrid Grid { get; set; }
    void MoveFocusBackward(MouseEventArgs e) {
        Grid.SetFocusedRowIndex(Grid.GetFocusedRowIndex() - 1);
    }
    void MoveFocusForward(MouseEventArgs e) {
        Grid.SetFocusedRowIndex(Grid.GetFocusedRowIndex() + 1);
    }
    void Grid_FocusedRowChanged(GridFocusedRowChangedEventArgs e) {
        PreviousEnabled = e.VisibleIndex != 0;
        NextEnabled = e.VisibleIndex != e.Grid.GetVisibleRowCount() - 1;
    }
    //...
}

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

See Also