Skip to main content

Standard Context Menus

  • 5 minutes to read

The Tree List control provides context menus for column headers, nodes, group summary footers, and the total summary footer.

To learn how to prevent these menus from opening, see Control the Availability of the Standard Context Menus to End-Users. For information on changing the menu functionality, see Customize the Standard Context Menus.

Node Menu

If the TreeList.OptionsMenu.EnableNodeMenu option is enabled, the tree list shows a context menu when a user right-clicks a node.

image

Predefined commands

The context menu contains the following predefined commands:

  • Collapse (Expand) — collapses (expands) the clicked node. This command is only shown when the node has children.
  • Full Collapse — collapses all nodes.
  • Full Expand — expands all nodes.

To hide these commands, use the TreeList.OptionsMenu.ShowExpandCollapseItems option.

If the control displays the New Item Row, the context menu also contains the following commands:

  • Add Node — creates a new node at the same level as the clicked node.
  • Add Child Node — creates a new child node for the clicked node.

To hide/show these commands regardless of whether the New Item Row is displayed, use the TreeList.OptionsMenu.ShowAddNodeItems option.

Localize the menu

The TreeListLocalizer allows you to localize the command captions. Use the following fields to identify a command:

  • MenuNodeCollapse — the Collapse command.
  • MenuNodeExpand — the Expand command.
  • MenuNodeExpandAll — the Full Expand command.
  • MenuNodeCollapseAll — the Full Collapse command.
  • MenuNodeAddNode — the Add Node command.
  • MenuNodeAddChildNode — the Add Child Node command.
using DevExpress.XtraTreeList.Localization;

TreeListLocalizer.Active = new NodeContextMenuLocalizer();

public class NodeContextMenuLocalizer : TreeListLocalizer {
    public override string Language { get { return "English"; } }
    public override string GetLocalizedString(TreeListStringId id) {
        switch (id) {
            case TreeListStringId.MenuNodeCollapse: return "Collapse this node";
            case TreeListStringId.MenuNodeExpand: return "Expand this node";
            case TreeListStringId.MenuNodeExpandAll: return "Expand all nodes";
            case TreeListStringId.MenuNodeCollapseAll: return "Collapse all nodes";
            default: return base.GetLocalizedString(id);
        }
    }
}

Populate the menu

You can handle the TreeList.PopupMenuShowing event to populate the menu with custom items.

using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Menu;

treeList1.PopupMenuShowing += OnPopupMenuShowing;

void OnPopupMenuShowing(object sender, PopupMenuShowingEventArgs e) {
    if (e.Menu is DevExpress.XtraTreeList.Menu.TreeListNodeMenu) {
        AddItem(e.Menu, NodeMenuItemID.Indent, treeList1.CanIndentNodes(treeList1.Selection));
        AddItem(e.Menu, NodeMenuItemID.Outdent, treeList1.CanOutdentNodes(treeList1.Selection));
        e.Allow = true;
    }
}

Note

Run the XtraTreeList demo and click Open Solution to see the complete example.

Column Header Menu

Users can right-click a column header to invoke this menu. Some items, however, can appear disabled, depending on the column’s settings.

image

The table below describes this menu’s items.

Menu Item Description
Sort Ascending Sorts data by the values of a column, in ascending order. The item is disabled if the context menu has been activated by clicking the header panel’s empty space. It is enabled if the clicked column’s TreeListOptionsColumn.AllowSort option is enabled.
Sort Descending Sorts data by the values of a column, in descending order. The item is disabled if the context menu has been activated by clicking the header panel’s empty space. It is enabled if the clicked column’s TreeListOptionsColumn.AllowSort option is enabled.
Column Chooser Invokes the Customization Form.
Best Fit Changes the width of a column to fit the contents of its cells (equivalent to calling the TreeListColumn.BestFit method for the column). It is disabled if the context menu has been activated by clicking the header panel’s empty space.
Best Fit (all columns) Changes the width of all columns to fit the contents of their cells (equivalent to calling the TreeList.BestFitColumns method).

Group Summary Menu

Users can right-click a group summary in a group footer to invoke this menu. The menu allows the user to clear or apply a summary.

image

The table below describes this menu’s items.

Menu Item Description
Sum Calculates the sum of a column’s values. Available for numeric columns only.
Min Returns the minimum of the column’s values.
Max Returns the maximum of the column’s values.
Count Calculates the number of rows affected by the group summary.
Average Calculates the average of the column’s values. Available for numeric columns only.
None Cancels summary calculations.

Total Summary Menu

Users can right-click a total summary in the summary footer to invoke this menu. The menu allows the user to clear or apply a summary.

image

The menu contains the same items as the Group Summary Menu plus one additional item:

Menu Item Description
All Nodes Switches the calculation of the current summary against all nodes, or only against root-level nodes.
See Also