Skip to main content
All docs
V25.2
  • TreeListDataRowCommandContext.DataItem Property

    Returns a data item bound to the target row.

    Namespace: DevExpress.Blazor

    Assembly: DevExpress.Blazor.v25.2.dll

    NuGet Package: DevExpress.Blazor

    Declaration

    public object DataItem { get; }

    Property Value

    Type Description
    Object

    A data item.

    Remarks

    The DevExpress Blazor TreeList allows you to display context menus with predefined and custom commands. Use the ContextMenus property to activate context menus for specific TreeList elements. Handle the CustomizeContextMenu event to modify the menu item collection. Use the Context event argument to identify the target TreeList element and obtain contextual information.

    When the target element is a data row cell, the Context property returns a TreeListDataRowCommandContext object. Use the object’s DataItem property to access a data item bound to the target row.

    Example

    The following code snippet adds a custom Delete command to the row context menu:

    @inject EmployeeTaskService EmployeeTaskService
    
    <DxTreeList Data="TreeListData"
                KeyFieldName="Id"
                ParentKeyFieldName="ParentId"
                ContextMenus="TreeListContextMenus.DataRow"
                CustomizeContextMenu="CustomizeContextMenu">
        <Columns>
            <DxTreeListDataColumn FieldName="Name" Caption="Task" />
            <DxTreeListDataColumn FieldName="EmployeeName" />
            <DxTreeListDataColumn FieldName="StartDate" />
            <DxTreeListDataColumn FieldName="DueDate" />
        </Columns>
    </DxTreeList>
    
    @code {
        List<EmployeeTask> TreeListData { get; set; }
    
        protected override void OnInitialized() {
            TreeListData = EmployeeTaskService.GenerateData();
        }
        void CustomizeContextMenu(TreeListCustomizeContextMenuEventArgs args) {
            if (args.Context is TreeListDataRowCommandContext rowContext) {
                args.Items.AddCustomItem("Delete", () => {
                    TreeListData.Remove((EmployeeTask)rowContext.DataItem);
                    args.TreeList.Reload();
                });
            }
        }
    }
    
    See Also