Skip to main content
All docs
V24.1

DxTreeList.GetDataItem(Int32) Method

Returns a data source item bound to the row with the specified visible index.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.1.dll

NuGet Package: DevExpress.Blazor

Declaration

public object GetDataItem(
    int visibleIndex
)

Parameters

Name Type Description
visibleIndex Int32

The row’s visible index.

Returns

Type Description
Object

The data item.

Remarks

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.

Note

When the TreeList is bound to the GridDevExtremeDataSource or loads data on demand, call the WaitForRemoteSourceRowLoadAsync(Int32) method before you execute the GetDataItem method to ensure that the specified data row is loaded.

The code snippet below performs the following actions:

  • Obtains a data item bound to the first visible row.
  • Returns the EmployeeName field value for this item.
<style>
    .my-button {
        width: 250px;
    }
</style>

<DxTreeList @ref="MyTreeList" Data="TreeListData" KeyFieldName="Id" ParentKeyFieldName="ParentId">
    <Columns>
        <DxTreeListDataColumn FieldName="Name" Caption="Task" />
        <DxTreeListDataColumn FieldName="StartDate" />
        <DxTreeListDataColumn FieldName="DueDate" />
    </Columns>
</DxTreeList>
<p />
<DxButton Click="OnGetDataItem" CssClass="my-button" Text="Get Data Item for the First Row" />
<p />
@Alert

@code {
    ITreeList MyTreeList { get; set; }
    object TreeListData { get; set; }
    public string Alert { get; set; } = "";

    void OnGetDataItem() {
        var fieldValue = MyTreeList.GetDataItemValue(MyTreeList.GetDataItem(0), "EmployeeName");
        Alert = $"The first row's Employee Name is '{fieldValue}'.";
    }
    protected override void OnInitialized() {
        TreeListData = new[] {
            new { Id = 1, ParentId = 0, Name = "Simplify & Clarify Product Messaging", EmployeeName = "John Heart", StartDate = new DateTime(2018, 4, 3), DueDate = new DateTime(2018, 4, 14)},
            new { Id = 2, ParentId = 1, Name = "Prepare Financial Reports", EmployeeName = "Samantha Bright", StartDate = new DateTime(2018, 4, 3), DueDate = new DateTime(2018, 4, 7)},
            new { Id = 3, ParentId = 1, Name = "Prepare Marketing Plan", EmployeeName = "Arthur Miller", StartDate = new DateTime(2018, 4, 7), DueDate = new DateTime(2018, 4, 14)},
            new { Id = 4, ParentId = 0, Name = "Create Action Plan To Improve Customer Engagement", EmployeeName = "Robert Reagan", StartDate = new DateTime(2017, 8, 8), DueDate = new DateTime(2018, 4, 8)},
            new { Id = 5, ParentId = 4, Name = "Update Personnel Files", EmployeeName = "Greta Sims", StartDate = new DateTime(2017, 8, 8), DueDate = new DateTime(2017, 10, 18)},
            new { Id = 6, ParentId = 4, Name = "Review Health Insurance Options", EmployeeName = "Brett Wade", StartDate = new DateTime(2017, 9, 27), DueDate = new DateTime(2017, 11, 10)},
            new { Id = 7, ParentId = 4, Name = "Choose Between PPO And HMO Health Plan", EmployeeName = "Sandra Johnson", StartDate = new DateTime(2017, 12, 13), DueDate = new DateTime(2018, 3, 23)},
            new { Id = 8, ParentId = 4, Name = "Update Google Adwords Strategy", EmployeeName = "Ed Holmes", StartDate = new DateTime(2017, 8, 23), DueDate = new DateTime(2017, 12, 23)},
            new { Id = 9, ParentId = 4, Name = "Create New Brochure Design", EmployeeName = "Barb Banks", StartDate = new DateTime(2018, 1, 3), DueDate = new DateTime(2018, 3, 14)},
            new { Id = 10, ParentId = 0, Name = "Increase Average Subscription Price", EmployeeName = "Wally Hobbs", StartDate = new DateTime(2017, 8, 9), DueDate = new DateTime(2017, 9, 13) }
        };
    }
}

TreeList - Get Data Item

See Also