Skip to main content
A newer version of this page is available. .

DxGrid.GetFocusedDataItem() Method

Returns a data item bound to the focused data row.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v22.2.dll

NuGet Package: DevExpress.Blazor

Declaration

public object GetFocusedDataItem()

Returns

Type Description
Object

A data item; null for a group row or if the Grid has no data to display.

Remarks

When the FocusedRowEnabled property is set to true, the grid displays the focused row. Call the GetFocusedDataItem method to get the data item bound to the focused data row. The method returns null in the following cases:

  • The currently focused row is a group row
  • The Grid has no data to display (for instance, when the applied filter has no matching data or data is not loaded to the grid)

To focus a row bound to the specified data item, call the SetFocusedDataItemAsync(Object) method. When the focused row changes, the grid raises the FocusedRowChanged event.

In the code sample below, the GetFocusedDataItem method is used to get additional information about the focused employee.

<DxGrid @ref="Grid" Id="grid" Data="GridData" PageSize="5" FocusedRowEnabled="true">
    <Columns>
        <DxGridDataColumn FieldName="FirstName" />
        <DxGridDataColumn FieldName="LastName" />
        <DxGridDataColumn FieldName="Title" />
        <DxGridDataColumn FieldName="HireDate" />
    </Columns>
</DxGrid>
<DxButton Text="Show Details" Click="ShowDetails"></DxButton>
<DxDropDown HeaderVisible="true" HeaderText="@MemoCaption" BodyText="@Notes" @bind-IsOpen=IsOpen 
            PositionMode="DropDownPositionMode.Center"  Width="500px" PositionTarget="#grid" />
@code {
    IGrid Grid { get; set; }
    string MemoCaption { get; set; }
    string Notes { get; set; }
    bool IsOpen { get; set; } = false;
    void ShowDetails(MouseEventArgs e) {
        if(Grid.GetFocusedDataItem() != null) {
            var employee = (Employee)Grid.GetFocusedDataItem();
            MemoCaption = employee.FirstName + " " + employee.LastName + " details:";
            Notes = employee.Notes;
            IsOpen = !IsOpen;
        }
    }
    object GridData { get; set; }
    protected override async Task OnInitializedAsync() {
        GridData = await NwindDataService.GetEmployeesAsync();
    }
}

Grid Focused Row

See Also