[Expand]General Information
[Collapse]WinForms Controls
  .NET Core Support
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications, and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Collapse]Data Grid
   [Expand]Get Started With Data Grid and Views
   [Expand]Data Binding
    Unbound Columns
   [Expand]Data Editing and Validation
   [Expand]Filter and Search
   [Expand]Focus and Selection Handling
    Format Cell Values
   [Expand]Master-Detail Relationships
   [Expand]Asynchronous Image Load
   [Expand]Export and Printing
   [Expand]Appearance and Conditional Formatting
    Split Presentation
    Row Preview Sections
   [Expand]Batch Modifications
    Hit Information
    Popup Menus
   [Expand]Save and Restore Layout
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]End-User Capabilities
    Included Components
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Gantt Control
  [Expand]Chart Control
  [Expand]Map Control
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Sunburst Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com

Popup Menus

This topic shows how to customize a Data Grid's built-in popup menus, override the default menu item actions, and use events to create custom popup menus.


This topic does not cover in-place editors' menu items.

In this topic:

Expanded Built-In Context Menus

The Data Grid's Grid Views and Banded Grid Views have five built-in context menus.

The properties the Views provide can affect the availability of certain items in these menus. For instance, when you disable the GridOptionsCustomization.AllowSort option, the "Sort Ascending" and "Sort Descending" items are automatically deactivated in the Column Header Menu.

Not all menu items can be hidden using the View's properties. To control the visibility of any menu item, use the GridView.PopupMenuShowing event as described below.

Expanded Customize, Hide and Disable Default Menu Items

To customize menu items (for example, change their captions and visibility), handle the GridView.PopupMenuShowing event. This event fires each time the menu is invoked.

The event's e.Menu parameter allows you to get the displayed menu. You can iterate through the e.Menu.Items collection or call the e.Menu.Find and e.Menu.FindAll methods to access individual menu items. To hide or remove certain menu items, use the e.Menu.Hide and e.Menu.Remove methods. These methods accept menu item identifiers as parameters. Refer to PopupMenuShowingEventArgs.Menu for information about menu item identification.

Expanded Example

The following code customizes the existing commands in the Data Grid's Column Header Menu by handling the GridView.PopupMenuShowing event:

  • Captions of the "Sort Ascending" and "Sort Descending" commands are replaced with custom strings;

  • A few commands are hidden;

  • Two "Best Fit" commands are disabled.

Expanded Add Custom Items to Built-In Menus

Handle the GridView.PopupMenuShowing event and add custom items to the event's e.Menu.Items parameter. You can use the following objects as custom items:

Expanded Example

The following example shows how to use the GridView.PopupMenuShowing event to create a custom menu in the Data Grid control. The created menu is displayed when you right-click within a data row or group row. It contains a 'Rows' submenu with a single "Delete this row" regular button, and a 'Cell Merging' check button.

A click on the 'Delete this row' button invokes the ColumnView.DeleteRow method. The 'Cell Merging' check button toggles the GridOptionsView.AllowCellMerge option.

Expanded Example

The following sample code handles the GridView.PopupMenuShowing event to customize the Column Header Context Menu before it is displayed. The code clears default menu items and adds a new command that locks a clicked column's position.

Expanded Change Menu Items' Default Behavior

A click on a menu item in the built-in context menus raises the GridView.GridMenuItemClick event. After your event handler is complete, the grid performs the menu item's related action by default. You can handle the GridMenuItemClick event to:

  • Perform custom actions
  • Prevent the default action from being invoked after your event handler is complete, by setting the event's Handled parameter to true.

Expanded Example

The following example handles the GridView.GridMenuItemClick event to show a warning when you select the "Hide This Column" command from the column header menu. Pressing 'No' in the message box cancels the invoked action.

Expanded Show a Custom Popup Menu for Any Grid Element

You can create and show a custom context menu within a View's BaseView.MouseDown event handler. When handling this event, identify the clicked element with the BaseView.CalcHitInfo method. This method returns information about a grid element at the specified screen point.

Use the GridViewMenu class to create a custom menu instance for Grid Views and Banded Grid Views. You can add the following menu item objects to the GridViewMenu.Items collection:

Expanded Example

This example creates a custom context menu that is displayed on right-clicking the Header Panel Button. This menu has two items: Columns and Runtime Column Customization. The first item is a sub menu that allows you to show/hide grid columns. The second item invokes the Customization Form.

Expanded Menu Appearance

By default, the Data Grid paints its menus according to the system settings, without taking into account the current skin.

To apply a skin to the Data Grid's menus, place a BarManager or RibbonControl component onto the form. This component is automatically bound to the Data Grid's EditorContainer.MenuManager property. The RibbonControl/BarManager now manages the display of the grid's menus, and applies the selected paint scheme (skin) to them.

The following image shows a column header menu painted using different themes.

You can use the Project Settings Page or the DefaultLookAndFeel component to customize the default paint scheme for all controls, including the data grid's popup menus.

Is this topic helpful?​​​​​​​