Skip to main content
All docs
V25.2
  • TreeListCustomizeContextMenuEventArgs.Items Property

    Contains context menu items.

    Namespace: DevExpress.Blazor

    Assembly: DevExpress.Blazor.v25.2.dll

    NuGet Package: DevExpress.Blazor

    Declaration

    public IContextMenuItemCollection Items { get; }

    Property Value

    Type Description
    IContextMenuItemCollection

    A context menu item collection.

    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.

    DevExpress Blazor TreeList - Context Menus

    Run Demo: Context Menu

    Handle the CustomizeContextMenu event to modify the menu item collection. The Items event argument stores commands to display in the context menu.

    Built-in Commands

    The initial Items collection depends on the menu type, TreeList settings, and component state. For instance, a header context menu contains the SortColumnAscending command only if sorting is allowed (on both TreeList and column levels). The ClearColumnSorting command is disabled if the target column is not sorted.

    The table below lists context menu types and built-in commands available in the TreeList:

    yes - The context menu includes this item by default.
    partially - You can add this item to the context menu.

    Menu Item Data Row Footer Header
    AutoFitAll partially partially yes
    ClearColumnSorting partially partially yes
    CollapseAll partially partially partially
    ExpandAll partially partially partially
    HideColumn partially partially yes
    ShowColumnChooser partially partially yes
    ShowFilterBuilder partially partially yes
    SortColumnAscending partially partially yes
    SortColumnDescending partially partially yes

    Example

    The following code snippet customizes commands available in the header context menu:

    @inject EmployeeTaskService EmployeeTaskService
    
    <DxTreeList Data="TreeListData"
                KeyFieldName="Id"
                ParentKeyFieldName="ParentId"
                ContextMenus="TreeListContextMenus.Header"
                CustomizeContextMenu="CustomizeContextMenu">
        <Columns>
            <DxTreeListSelectionColumn Width="80px" />
            <DxTreeListDataColumn FieldName="Name" Caption="Task" ShowInColumnChooser="false"/>
            <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 TreeListHeaderCommandContext headerContext) {
                // Customizes context menu commands for the Task column header
                if (headerContext.Column is ITreeListDataColumn dataColumn && dataColumn.Caption == "Task") {
                    args.Items.Remove(TreeListContextMenuDefaultItemNames.HideColumn);
                }
                // Customizes context menu commands for the selection column header
                if (headerContext.Column is ITreeListSelectionColumn selectionColumn) {
                    var isFixed = selectionColumn.FixedPosition != TreeListColumnFixedPosition.None;
                    string itemText = isFixed ? "Unfix Column" : "Fix Column to the Left";
                    var newValue = isFixed ? TreeListColumnFixedPosition.None : TreeListColumnFixedPosition.Left;
    
                    args.Items.AddCustomItem(itemText, () => {
                        headerContext.TreeList.BeginUpdate();
                        selectionColumn.FixedPosition = newValue;
                        headerContext.TreeList.EndUpdate();
                    });
                }
            }
        }
    }
    
    See Also