Back to Devexpress

GridView.GridMenuItemClick Event

windowsforms-devexpress-dot-xtragrid-dot-views-dot-grid-dot-gridview-cf00933e.md

latest6.5 KB
Original Source

GridView.GridMenuItemClick Event

Enables you to provide custom responses to clicking context menu items.

Namespace : DevExpress.XtraGrid.Views.Grid

Assembly : DevExpress.XtraGrid.v25.2.dll

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

Declaration

csharp
[DXCategory("Behavior")]
public event GridMenuItemClickEventHandler GridMenuItemClick
vb
<DXCategory("Behavior")>
Public Event GridMenuItemClick As GridMenuItemClickEventHandler

Event Data

The GridMenuItemClick event's data class is GridMenuItemClickEventArgs. The following properties provide information specific to this event:

PropertyDescription
AutoFilterConditionGets the currently processed filter condition (when the GridMenuItemClick event fires for items in the auto-filter row‘s menu).
ColumnGets the column whose footer cell or header was clicked to invoke a context menu.
DXMenuItemGets the clicked menu item.
HandledGets or sets a value specifying whether default menu item click processing is required after event handler execution.
MenuItemObsolete. This property is obsolete.
MenuTypeGets the type of the context menu whose item was clicked.
SummaryFormatGets or sets the summary value formatting.
SummaryItemGets a summary item object corresponding to the footer cell whose menu’s item was clicked.
SummaryItemsGets the View’s group summary items collection.
SummaryTypeGets the summary type which is about to be applied.

Remarks

The GridMenuItemClick event is fired in response to clicking a menu item. It enables you to cancel default actions performed when clicking a particular item and provide your own item handling. You can also perform actions as well as the default processing. For instance, you may update a summary item’s formatting when end-users change the summary type using context menus.

Note : the GridMenuItemClick event is not raised when clicking menu items that are created manually in your GridView.PopupMenuShowing event handler.

Example

The following code demonstrates how to use the GridView.GridMenuItemClick event to customize a specific column’s summary. The code determines for which column a menu is activated, and if this column’s GridColumn.FieldName property value is “UnitPrice” and the menu type is a footer menu and an item clicked is not “Count”, then the text displayed in the summary footer under the “UnitPrice” column is formatted to display the summary value in currency format:

csharp
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Localization;

//...
private void gridView_GridMenuItemClick(object sender, GridMenuItemClickEventArgs e) {
    string sumFormat; 
    int subSumFormat;
    //Summary format is only adjusted for the UnitPrice column, 
    // if its summary type is not Count
    if(e.MenuType != GridMenuType.Summary || e.DXMenuItem.Tag.Equals(
      GridStringId.MenuFooterCount)) return;
    if(e.Column.FieldName == "UnitPrice") {
        sumFormat = e.SummaryFormat;
        //Find the summary value placeholder
        subSumFormat = sumFormat.IndexOf("0");
        //Custom format string
        if(subSumFormat > 0) sumFormat = sumFormat.Substring(0, subSumFormat) + "0:c}";
        //Update the summary format string
        e.SummaryFormat = sumFormat;
    }
}
vb
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraGrid.Localization
'...
Private Sub gridView_GridMenuItemClick(ByVal sender As Object, _
  ByVal e As GridMenuItemClickEventArgs) Handles gridView1.GridMenuItemClick
    Dim sumFormat As String
    Dim subSumFormat As Integer
    'Summary format is only adjusted for the UnitPrice column, _
    ' if its summary type is not Count
    If e.MenuType <> GridMenuType.Summary Or _
      e.DXMenuItem.Tag.Equals(GridStringId.MenuFooterCount) Then Exit Sub
    If e.Column.FieldName = "UnitPrice" Or e.Column.FieldName = "SubTotal" Then
        sumFormat = e.SummaryFormat
        'Find the summary value placeholder
        subSumFormat = sumFormat.IndexOf("0")
        'Custom format string
        If subSumFormat > 0 Then sumFormat = sumFormat.Substring(0, subSumFormat) + "0:c}"
        'Update the summary format string
        e.SummaryFormat = sumFormat
    End If
End Sub

See Also

PopupMenuShowing

Popup and Context Menus

GridView Class

GridView Members

DevExpress.XtraGrid.Views.Grid Namespace