Back to Devexpress

PopupMenuShowingEventArgs.Menu Property

windowsforms-devexpress-dot-xtratreelist-dot-popupmenushowingeventargs-5a456b5b.md

latest4.8 KB
Original Source

PopupMenuShowingEventArgs.Menu Property

Gets or sets the control’s popup menu that will be shown.

Namespace : DevExpress.XtraTreeList

Assembly : DevExpress.XtraTreeList.v25.2.dll

NuGet Packages : DevExpress.Win.Navigation, DevExpress.Win.TreeList

Declaration

csharp
public TreeListMenu Menu { get; set; }
vb
Public Property Menu As TreeListMenu

Property Value

TypeDescription
DevExpress.XtraTreeList.Menu.TreeListMenu

A TreeListMenu object that is the menu that will be shown.

|

Remarks

The Menu property allows you to add or remove items from the control’s popup menu.

You can use e.Menu.Hide and e.Menu.Remove methods to hide and remove menu items or the e.Menu.Find method to obtain a specific menu item and modify it.

An empty menu is not displayed.

Example

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.

csharp
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);
    }
}
vb
Private Sub TreeList1_PopupMenuShowing(ByVal sender As Object, ByVal e As PopupMenuShowingEventArgs)
    ' Disable Min and Max items in the summary footer menu for the "Department" column:
    If e.MenuType = TreeListMenuType.Summary AndAlso e.HitInfo.Column.FieldName = NameOf(SalesData.Department) Then
        e.Menu.Find(TreeListStringId.MenuFooterMax).Enabled = False
        e.Menu.Find(TreeListStringId.MenuFooterMin).Enabled = False
    End If
    ' Remove the "Column Chooser" item from the column header menu:
    If e.MenuType = TreeListMenuType.Column Then
        e.Menu.Remove(TreeListStringId.MenuColumnColumnCustomization)
        e.Menu.Remove(TreeListStringId.MenuColumnBandCustomization)
    End If
End Sub

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Menu property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-treelist-customize-node-menu/CS/Form1.cs#L46

csharp
private void treeList1_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e) {
    if(e.Menu is TreeListNodeMenu) {
        treeList1.FocusedNode = ((TreeListNodeMenu)e.Menu).Node;

winforms-treelist-customize-node-menu/VB/Form1.vb#L48

vb
Private Sub treeList1_PopupMenuShowing(ByVal sender As Object, ByVal e As PopupMenuShowingEventArgs)
    If TypeOf e.Menu Is TreeListNodeMenu Then
        treeList1.FocusedNode = CType(e.Menu, TreeListNodeMenu).Node

See Also

PopupMenuShowingEventArgs Class

PopupMenuShowingEventArgs Members

DevExpress.XtraTreeList Namespace