TreeList.PopupMenuShowing Event
Allows you to customize default context menus or invoke custom menus.
Namespace: DevExpress.XtraTreeList
Assembly: DevExpress.XtraTreeList.v24.2.dll
Declaration
Event Data
The PopupMenuShowing event's data class is PopupMenuShowingEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Allow | Gets or sets whether to display the context menu. Inherited from BasePopupMenuShowingEventArgs. |
HitInfo | Provides access to information about the clicked visual element. |
Menu | Gets or sets the control’s popup menu that will be shown. |
MenuType | Gets the type of the context menu that is about to be shown. |
Point | Gets or sets coordinates of the invoked context menu (top-left corner) relative to the parent control. Inherited from BasePopupMenuShowingEventArgs. |
ScreenPoint | Gets coordinates of the invoked context menu (top-left corner) relative to the screen. Inherited from BasePopupMenuShowingEventArgs. |
The event data class exposes the following methods:
Method | Description |
---|---|
ShowCustomMenu(IDXDropDownControlEx) | Invokes a custom context menu instead of the control’s menu. Inherited from BasePopupMenuShowingEventArgs. |
ShowCustomMenu(ContextMenuStrip) | Invokes a custom context menu instead of the control’s menu. Inherited from BasePopupMenuShowingEventArgs. |
Remarks
The Tree List shows a context menu when the user right-clicks within the following areas:
- Column Header — the control shows the Column Header Context Menu if the EnableColumnMenu option is enabled. The menu contains commands related to columns: sorting, filtering, etc.
- Node — the control shows the Node Context Menu if the EnableNodeMenu option is enabled. The menu contains commands related to nodes: expand, collapse, create a new node, etc.
- Group Footer, Summary Footer — the control shows the Footer Context Menu if the EnableFooterMenu option is enabled. The menu contains commands related to summaries: sum, min, average, etc.
- Empty Area — the menu invoked with a right-click below the tree list’s nodes. The default empty-area context menu does not contain any commands. Use the
PopupMenuShowing
event to populate the menu.
Refer to the following help topic for more information: Context Menus.
Examples
The following code sample invokes a custom context menu when a user right-clicks a column header:
Add a BarManager to the form and create a custom PopupMenu as demonstrated in the following help topic: Popup Menus:
Handle the
TreeList.PopupMenuShowing
event and call the e.ShowCustomMenu method to display your custom menu instead of the default menu.
void TreeList1_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e) {
if (e.MenuType == TreeListMenuType.Column) {
popupMenu_Column.Tag = e.HitInfo;
popupMenu_Column.MenuCaption = $"{e.HitInfo.Column}";
e.ShowCustomMenu(popupMenu_Column);
}
}
TreeListHitInfo GetHitInfo(BarItemLink link) {
PopupMenu menu = link.LinkedObject as PopupMenu;
return menu.Tag as TreeListHitInfo;
}
void barButtonItem_Filter_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) {
TreeListHitInfo info = GetHitInfo(e.Link);
info.Column.TreeList.ShowFilterEditor(info.Column);
}
void barButtonItem_ColumnChooser_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) {
TreeListHitInfo info = GetHitInfo(e.Link);
info.Column.TreeList.ShowCustomization();
}
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.
using DevExpress.Utils.Menu;
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Columns;
//...
void treeList1_PopupMenuShowing(object sender, DevExpress.XtraTreeList.PopupMenuShowingEventArgs e) {
if (e.MenuType == TreeListMenuType.Summary && e.HitInfo.HitInfoType == HitInfoType.SummaryFooter) {
DXMenuItem menuItem = new DXMenuItem("Clear All", clearAllMenuItemClick);
menuItem.Tag = e.HitInfo.Column;
e.Menu.Items.Add(menuItem);
}
}
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;
}
The following sample code handles the TreeList.PopupMenuShowing
event to execute the following actions:
- Disable Min and Max items in the summary footer context menu for the “Department” column.
- Remove the Column Chooser item from the column header context menu.
void TreeList1_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e) {
// Disable Min and Max items in the summary footer menu for the "Department" column:
if (e.MenuType == TreeListMenuType.Summary && e.HitInfo.Column.FieldName == nameof(SalesData.Department)) {
e.Menu.Find(TreeListStringId.MenuFooterMax).Enabled = false;
e.Menu.Find(TreeListStringId.MenuFooterMin).Enabled = false;
}
// Remove the "Column Chooser" item from the column header menu:
if (e.MenuType == TreeListMenuType.Column) {
e.Menu.Remove(TreeListStringId.MenuColumnColumnCustomization);
e.Menu.Remove(TreeListStringId.MenuColumnBandCustomization);
}
}