Back to Devexpress

GridControl.PopupMenuCustomization Event

xamarin-devexpress-dot-mobile-dot-datagrid-dot-gridcontrol-39695d69.md

latest5.6 KB
Original Source

GridControl.PopupMenuCustomization Event

Enables you to customize the grid’s popup menus.

Namespace : DevExpress.Mobile.DataGrid

Assembly : DevExpress.Mobile.Grid.v18.2.dll

Declaration

csharp
public event PopupMenuEventHandler PopupMenuCustomization
vb
Public Event PopupMenuCustomization As PopupMenuEventHandler

Event Data

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

PropertyDescription
ColumnGets the column for which the popup menu will be shown.
MenuProvides access to the grid’s popup menu to be shown.
MenuTypeGets the type of the grid’s menu to be invoked.
RowHandleGets the handle of the row for which the popup menu will be shown.

Remarks

Important

This documentation topic describes legacy technology. We no longer develop new functionality for the GridControl and suggest that you use the new DataGridView control instead.

The GridControl provides a set of built-in popup menus enabling end-users to manage data rows (edit and delete them), sort and group data, show and hide columns, modify total and group summaries. Available menu types are listed by the GridPopupMenuType enumerator.

The PopupMenuCustomization event allows you to customize any of these menus. For example, you can remove existing menu items and/or add new custom items.

The following properties allow you to disable a grid’s menu:

Example

The following sample code handles the GridControl.PopupMenuCustomization event to customize the data row popup menu before it is displayed. The code clears default menu items and adds new ones. One of these custom items applies a specific filter to the grid data and another one clears this filter.

csharp
using DevExpress.Mobile.DataGrid;
using DevExpress.Mobile.Core;
// ...

void OnPopupMenuCustomization(object sender, PopupMenuEventArgs e) {
    if (e.MenuType == GridPopupMenuType.DataRow) {
        e.Menu.Items.Clear();
        PopupMenuItem itemFilter = new PopupMenuItem();
        itemFilter.Caption = "Filter by Product";
        itemFilter.Click += ItemFilterClick;
        e.Menu.Items.Insert(0, itemFilter);

        PopupMenuItem itemClearFilter = new PopupMenuItem();
        itemClearFilter.Caption = "Clear Filter";
        itemClearFilter.Click += ItemClearFilterClick;
        e.Menu.Items.Insert(1, itemClearFilter);
    }
}

void ItemFilterClick(object sender, EventArgs e) {
    IRowData rowData = grid.GetRow(grid.SelectedRowHandle);
    Order selectedOrder = rowData.DataObject as Order;
    string productName = selectedOrder.Product.Name;
    grid.Columns ["Product.Name"].AutoFilterValue = productName;
}

void ItemClearFilterClick(object sender, EventArgs e) {
    grid.ClearFilter ();
}
xaml
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
             x:Class="HelloGrid.MainPage"
             xmlns:dxg="clr-namespace:DevExpress.Mobile.DataGrid;assembly=DevExpress.Mobile.Grid.v15.1">
    <ContentPage.Padding>
        <OnPlatform x:TypeArguments="Thickness" iOS="0, 20, 0, 0" />
    </ContentPage.Padding>

    <ContentPage.Content>
        <dxg:GridControl x:Name="grid" ItemsSource="{Binding Orders}" 
                         PopupMenuCustomization="OnPopupMenuCustomization">

          <dxg:GridControl.Columns>
              <dxg:TextColumn FieldName="Product.Name" Caption="Product"/>
              <dxg:NumberColumn FieldName="Product.UnitPrice" Caption="Price" DisplayFormat="C0"/>
              <dxg:NumberColumn FieldName="Quantity" />
              <dxg:NumberColumn FieldName="Total"
                                UnboundType="Decimal" UnboundExpression="[Quantity] * [Product.UnitPrice]"
                                IsReadOnly="True" DisplayFormat="C0"/>
          </dxg:GridControl.Columns>
    </dxg:GridControl>
    </ContentPage.Content>
</ContentPage>

See Also

GridControl Class

GridControl Members

DevExpress.Mobile.DataGrid Namespace