Back to Devexpress

DxTreeList.GetDataItem(Int32) Method

blazor-devexpress-dot-blazor-dot-dxtreelist-dot-getdataitem-x28-system-dot-int32-x29.md

latest3.2 KB
Original Source

DxTreeList.GetDataItem(Int32) Method

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

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
public object GetDataItem(
    int visibleIndex
)

Parameters

NameTypeDescription
visibleIndexInt32

The row’s visible index.

|

Returns

TypeDescription
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.

  • Razor

  • CSS

razor
<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}'.";
    }
}
css
.my-button {
    width: 250px;
}

Implements

GetDataItem(Int32)

GetDataItem(Int32)

See Also

DxTreeList Class

DxTreeList Members

DevExpress.Blazor Namespace