KB Article A990
Visible to All Users

How to add a new item to the grid's popup menu

Description:
I would like to customize the standard context menu which appears when I right click the grid. How this can be done?

Answer:
Below you will find some sample code which demonstrates how to create a new MenuItem and add it to the grid's FooterMenu. Note, its class structure does not allow you to identify the menu object that this item belongs to. So, we suggest that you use the Item's Tag property and save the menu to it. Here is some sample code:

Visual Basic
Private Sub GridView1_PopupMenuShowing(ByVal sender As System.Object, _ ByVal e As DevExpress.XtraGrid.Views.Grid.GridMenuEventArgs) Handles GridView1.ShowGridMenu If e.MenuType <> DevExpress.XtraGrid.Views.Grid.GridMenuType.Summary Then Exit Sub Dim footerMenu As DevExpress.XtraGrid.Menu.GridViewFooterMenu = CType(e.Menu, DevExpress.XtraGrid.Menu.GridViewFooterMenu) Dim menuItem As New DevExpress.Utils.Menu.DXMenuItem("MyItem", New EventHandler(AddressOf MyMenuItem)) menuItem.Tag = e.Menu footerMenu.Items.Add(menuItem) End Sub Private Sub MyMenuItem(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim Item As DevExpress.Utils.Menu.DXMenuItem = CType(sender, DevExpress.Utils.Menu.DXMenuItem) Dim menu As DevExpress.XtraGrid.Menu.GridViewFooterMenu = CType(Item.Tag, DevExpress.XtraGrid.Menu.GridViewFooterMenu) MessageBox.Show(menu.View.FocusedColumn.Caption) End Sub

Besides, we suggest that you review the Implementing Custom Behavior for Popup Menus topic in the XtraGrid help and FixedColumns module of the GridMainDemo demo project.
See Also:
PopupMenuShowing
How to disable particular menu items in the default grid menus

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.