Skip to main content
A newer version of this page is available. .

How to: Add custom menu items to the standard menus

  • 2 minutes to read

The following example demonstrates how to add a custom item to a standard context menu and handle the click event for this item. The TreeList.PopupMenuShowing event is handled to add the Clear All item to the summary footer menu. Clicking this item cancels the summary calculations for all Tree List columns.

ContextMenus - CustomItemClick

using DevExpress.Utils.Menu;
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Columns;
//...
private void treeList1_PopupMenuShowing(object sender, DevExpress.XtraTreeList.PopupMenuShowingEventArgs e) {
    TreeList tL = sender as TreeList;
    TreeListHitInfo hitInfo = tL.CalcHitInfo(e.Point);
    if (hitInfo.HitInfoType == HitInfoType.SummaryFooter) {
        DXMenuItem menuItem = new DXMenuItem("Clear All", new EventHandler(this.clearAllMenuItemClick));
        menuItem.Tag = hitInfo.Column;
        e.Menu.Items.Add(menuItem);
    }
}

private void clearAllMenuItemClick(object sender, EventArgs e) {
    TreeListColumn clickedColumn = (sender as DXMenuItem).Tag as TreeListColumn;
    if (clickedColumn == null) return;
    TreeList tl = clickedColumn.TreeList;
    foreach (TreeListColumn column in tl.Columns)
        column.SummaryFooter = SummaryItemType.None;
}