Current filter:
                                You should refresh the page.
                                Support Center
                                0
                                  • 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.

                                You must  log in  or  register  to leave comments

                                1 Solution

                                0

                                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_ShowGridMenu(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; } }
                                	
                                [VB.NET]
                                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_ShowGridMenu(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

                                • David Lemieux 02.06.2013

                                  This code is very weak. These handlers will fail if another handler changed the caption before.

                                • Hi Crono,

                                  Yes, you are right. Since a menu item caption is changed in your code, you can search for a changed caption in menu items. Another approach is to use the Tag property. A GridStringId value corresponding to the menu item is set to the item Tag.

                                  private DXMenuItem GetItemByStringId(DXPopupMenu menu, GridStringId id) {
                                              foreach (DXMenuItem item in menu.Items) {
                                                  if ((GridStringId)item.Tag == id) {
                                                      return item;
                                                  }
                                              }
                                              return null;
                                          }
                                  
                                You must  log in  or  register  to leave comments

                                To start a chat you should create a support ticket


                                If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

                                FOLLOW US

                                DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, Silverlight, ASP.NET, WinForms, HTML5 or Windows 8, DevExpress tools help you build and deliver your best in the shortest time possible.

                                Copyright © 1998-2014 Developer Express Inc.
                                All trademarks or registered trademarks are property of their respective owners