KB Article A47
Visible to All Users

How to disable particular menu items in the default grid menus

Description:
Is there a way to disable some of the default items that show on a column context menu? In particular, I would like to either disable or completely remove the "Runtime Column Customization" option.

Answer:
Yes, you can disable or hide menu items. Please use the ShowGridMenu event for this. Also, please note that starting from the 10.2 version, the GridView's ShowGridMenu event is marked obsolete, so it needs to use the PopupMenuShowing event.
Here is sample code:

C#
using DevExpress.Utils.Menu; using DevExpress.XtraGrid.Localization; using DevExpress.XtraGrid.Views.Grid; private DXMenuItem GetItemByStringId(DXPopupMenu menu, GridStringId id) { foreach ( DXMenuItem item in menu.Items ) if ( item.Caption == GridLocalizer.Active.GetLocalizedString(id) ) return item; return null; } private void gridView1_PopupMenuShowing(object sender, DevExpress.XtraGrid.Views.Grid.GridMenuEventArgs e) { if ( e.MenuType == GridMenuType.Column ) { // Customize DXMenuItem miCustomize = GetItemByStringId(e.Menu, GridStringId.MenuColumnColumnCustomization); if ( miCustomize != null ) miCustomize.Visible = false; // Group By This Column DXMenuItem miGroup = GetItemByStringId(e.Menu, GridStringId.MenuColumnGroup); if ( miGroup != null ) miGroup.Enabled = false; } }
Visual Basic
Imports DevExpress.Utils.Menu Imports DevExpress.XtraGrid.Localization Imports DevExpress.XtraGrid.Views.Grid Private Function GetItemByStringId(ByVal menu As DXPopupMenu, ByVal id As GridStringId) As DXMenuItem For Each item As DXMenuItem In menu.Items If item.Caption = GridLocalizer.Active.GetLocalizedString(id) Then Return item End If Next item Return Nothing End Function Private Sub gridView1_PopupMenuShowing(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Grid.GridMenuEventArgs) If e.MenuType = GridMenuType.Column Then ' Customize Dim miCustomize As DXMenuItem = GetItemByStringId(e.Menu, GridStringId.MenuColumnColumnCustomization) If miCustomize IsNot Nothing Then miCustomize.Visible = False End If ' Group By This Column Dim miGroup As DXMenuItem = GetItemByStringId(e.Menu, GridStringId.MenuColumnGroup) If miGroup IsNot Nothing Then miGroup.Enabled = False End If End If End Sub

See Also:
How to add a new item to the grid's popup menu
How to show a context menu for grid rows

Show previous comments (3)
DevExpress Support Team 11 years ago

    Hello,
    To process your inquiry in the most efficient manner, I've moved it to a separate thread and forwarded to the WPF team:
    How to disable particular menu items in the default grid menus
    Please refer to it for further correspondence.

      in the newest version ShowGridMenu and PopupMenuShowing event do not exist anymore ?
      How to do this in the newest version ?

      DevExpress Support Team 9 years ago

        Hello,

        To process your recent post more efficiently, I created a separate ticket on your behalf: T350155: XtraGridControl version 15.2 - Cannot find the ShowGridMenu and PopupMenuShowing events. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.