Skip to main content
A newer version of this page is available. .

PivotGridControl.PopupMenuShowing Event

Allows you to customize context menus.

Namespace: DevExpress.Xpf.PivotGrid

Assembly: DevExpress.Xpf.PivotGrid.v18.2.dll

Declaration

public event PopupMenuShowingEventHandler PopupMenuShowing

Event Data

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

Property Description
Customizations Allows you to customize the context menu by adding new menu items or removing existing items.
Handled Gets or sets a value that indicates the present state of the event handling for a routed event as it travels the route. Inherited from RoutedEventArgs.
Items Gets a collection of items contained within the context menu.
MenuType Gets what kind of pivot grid element invokes the menu.
OriginalSource Gets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class. Inherited from RoutedEventArgs.
RoutedEvent Gets or sets the RoutedEvent associated with this RoutedEventArgs instance. Inherited from RoutedEventArgs.
Source Gets the PivotGridControl that raised the event.
TargetElement Gets the UI element for which the context menu is shown.

The event data class exposes the following methods:

Method Description
GetCellInfo() Returns information about the cell for which the menu is invoked.
GetFieldInfo() Returns information about the field for whose header the menu is invoked.
GetFieldValueInfo() Returns information about the field value for which the menu is invoked.
InvokeEventHandler(Delegate, Object) When overridden in a derived class, provides a way to invoke event handlers in a type-specific way, which can increase efficiency over the base implementation. Inherited from RoutedEventArgs.
OnSetSource(Object) When overridden in a derived class, provides a notification callback entry point whenever the value of the Source property of an instance changes. Inherited from RoutedEventArgs.

Remarks

The PopupMenuShowing event is raised when an end-user invokes a context menu.

Use the event parameter’s PopupMenuShowingEventArgs.Customizations property to add new and remove existing menu items. This property provides access to a collection of actions that allow you to customize the context menu. To learn more, see Context Menus, Items and Links and Bar Actions.

To determine for what kind of pivot grid element (a cell, a field value, a field header or the field header area) the menu is invoked, use the PopupMenuShowingEventArgs.MenuType property. To obtain the actual visual element for which the menu is invoked, use the PopupMenuShowingEventArgs.TargetElement property.

Use the following methods to obtain additional information about this visual element.

PopupMenuShowingEventArgs.GetCellInfo

Returns information about the cell for which the menu is invoked.

PopupMenuShowingEventArgs.GetFieldValueInfo

Returns information about the field value for which the menu is invoked.

PopupMenuShowingEventArgs.GetFieldInfo

Returns information about the field for whose header the menu is invoked.

Example

This example demonstrates how to handle the PivotGridControl.PopupMenuShowing event to create a context menu item with a command that displays the Top N Values for the selected row or column.

To determine whether the context menu appears for the Field Value, cast the PopupMenuShowingEventArgs.TargetElement to the FieldValueElement type. If the cast is successful, the resulting object’s DataAreaElement.ElementData property provides access to the FieldValueElementData object containing information on the target field.

Create a new bar item of the BarButtonItem type and store the FieldValueElementData object in the Tag property. Assign a custom handler to the BarItem.ItemClick event and add the bar item to the PopupMenuShowingEventArgs.Customizations collection.

Menu item’s BarItem.ItemClick event handler retrieves the previously saved FieldValueElementData object from the bar item’s Tag property. Subsequently, it uses the FieldValueElementData.PivotGrid property to get access to the PivotGridControl and call the PivotGridControl.GetFieldsByArea method to get all fields by area. The target field and its characteristics are obtained from the FieldValueElementData.Field, FieldValueElementData.DataField, and FieldValueElementData.MaxIndex properties. The PivotGridField.TopValueCount property value specifies the number of values to display.

FieldValueElementData_PopupMenuShowing

Note

The complete sample project How to Implement a Context Menu Action to Display Top 5 Values in a Column or Row is available in the DevExpress Examples repository.

The following code snippets (auto-collected from DevExpress Examples) contain references to the PopupMenuShowing event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also