Skip to main content
All docs
V24.1

DxTreeList.GetFocusedRowIndex() Method

Returns the visible index of the focused row.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.1.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 the TreeList displays no rows.

Remarks

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

When the focused row changes, the TreeList 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, GetFocusedRowIndex() and SetFocusedRowIndex(Int32) methods move focus between rows:

@inject EmployeeTaskService EmployeeTaskService

<div class="d-flex py-2">
    <DxButton Text="Previous" Click="MoveFocusBackward" Enabled="PreviousEnabled" />
    <DxButton Text="Next" Click="MoveFocusForward" Enabled="NextEnabled" CssClass="mx-2" />
</div>
<DxTreeList @ref="TreeList"
            Data="TreeListData"
            KeyFieldName="Id"
            ParentKeyFieldName="ParentId"
            FocusedRowEnabled="true"
            FocusedRowChanged="TreeList_FocusedRowChanged">
    <Columns>
        <DxTreeListDataColumn FieldName="Name" Caption="Task" />
        <DxTreeListDataColumn FieldName="EmployeeName" />
        <DxTreeListDataColumn FieldName="StartDate" />
        <DxTreeListDataColumn FieldName="DueDate" />
    </Columns>
</DxTreeList>

@code {
    bool PreviousEnabled { get; set; }
    bool NextEnabled { get; set; }
    ITreeList TreeList { get; set; }
    List<EmployeeTask> TreeListData { get; set; }

    protected override void OnInitialized() {
        TreeListData = EmployeeTaskService.GenerateData();
    }
    void MoveFocusBackward(MouseEventArgs e) {
        TreeList.SetFocusedRowIndex(TreeList.GetFocusedRowIndex() - 1);
    }
    void MoveFocusForward(MouseEventArgs e) {
        TreeList.SetFocusedRowIndex(TreeList.GetFocusedRowIndex() + 1);
    }
    void TreeList_FocusedRowChanged(TreeListFocusedRowChangedEventArgs e) {
        PreviousEnabled = e.VisibleIndex != 0;
        NextEnabled = e.VisibleIndex != e.TreeList.GetVisibleRowCount() - 1;
    }
}

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

See Also