Skip to main content
All docs
V24.2

DxTreeList.GetFocusedDataItem() Method

Returns a data item bound to the focused data row.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

Declaration

public object GetFocusedDataItem()

Returns

Type Description
Object

If a data row is focused, the method returns the data item bound to this row. The method returns null if the TreeList displays no rows.

Remarks

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

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

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

Obtain Item Field Values

Pass a data item to the GetDataItemValue method to get the item’s field value when the TreeList is bound to a collection of anonymous objects. In other cases, you can cast a data item to the corresponding type and use the {DataItem.FieldName} notation to get the item’s field value.

The following code sample uses the GetFocusedDataItem method to get information about the focused task:

@inject EmployeeTaskService EmployeeTaskService

<style>
    .my-button {
        width: 200px;
    }
</style>

<DxTreeList @ref="MyTreeList"
            Data="TreeListData"
            KeyFieldName="Id"
            ParentKeyFieldName="ParentId"
            FocusedRowEnabled="true">
    <Columns>
        <DxTreeListDataColumn FieldName="Name" Caption="Task" />
        <DxTreeListDataColumn FieldName="EmployeeName" />
        <DxTreeListDataColumn FieldName="StartDate" />
        <DxTreeListDataColumn FieldName="DueDate" />
    </Columns>
</DxTreeList>
<p />
<DxButton Click="GetFocusedTask" CssClass="my-button" Text="Get the Focused Task" />
<p />
@Alert

@code {
    ITreeList MyTreeList { get; set; }
    List<EmployeeTask> TreeListData { get; set; }
    public string Alert { get; set; } = "";

    protected override void OnInitialized() {
        TreeListData = EmployeeTaskService.GenerateData();
    }
    void GetFocusedTask(MouseEventArgs e) {
        if (MyTreeList.GetFocusedDataItem() != null) {
            var task = (EmployeeTask)MyTreeList.GetFocusedDataItem();
            Alert = $"The '{task.Name}' task is focused.";
        }
    }
}

TreeList Focused Row

See Also