Skip to main content

FilterControl.PopupMenuShowing Event

Fires when any popup menu in a FilterControl is about to be displayed, and allows you to customize these menus.

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.XtraEditors.v24.1.dll

NuGet Package: DevExpress.Win.Navigation

Declaration

[DXCategory("Events")]
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
Cancel Gets or sets a value indicating whether the event should be canceled. Inherited from CancelEventArgs.
CurrentNode Gets the node where the menu is to be displayed.
FocusedElementType Gets the type of the Filter Control’s element where the menu is to be displayed.
Menu Gets the menu that will be invoked.
MenuType Gets the type of the FilterControl’s menu to be invoked.
Point Gets the position where the menu is to be invoked.
RestoreMenu Gets or sets whether the current menu should be restored to its default state, after it has been displayed on-screen.

Remarks

The e.Menu parameter allows you to identify which of the FilterControl menus is about to open.

group

nodeaction

This menu is available when the FilterControl.ShowGroupCommandsIcon option is enabled.

column

clause

The number of DateTime-specific operators depends on the FilterControl.ShowDateTimeFunctions property value.

columnfunctions

This menu allows users to compare a target field with other fields (FilterControl.ShowOperandTypeIcon) or DateTime constants (FilterControl.ShowDateTimeConstants).

image

This menu is available when a data source has collection properties, and the FilterControl.AllowAggregateEditing equals Aggregate or AggregateWithCondition.

image

This menu is available when a data source has collection properties, and the FilterControl.AllowAggregateEditing equals Aggregate or AggregateWithCondition.

Methods and parameters

Use the following methods to find and customize menu items:

  • e.Menu.Find - returns a DXMenuItem object that you can customize;
  • e.Menu.Hide - hides a menu item;
  • e.Menu.Remove - removes a menu item.

To forcibly close a menu, set the e.Cancel parameter to true.

Example 1: Group operator menu

To customize “And”, “Or”, “Not And”, and “Not Or” operators, use DevExpress.Data.Filtering.Helpers.GroupType enumeration values. Other menu items are identified as StringID values:

  • DevExpress.XtraEditors.Controls.StringId.FilterMenuConditionAdd;
  • DevExpress.XtraEditors.Controls.StringId.FilterMenuGroupAdd;
  • DevExpress.XtraEditors.Controls.StringId.FilterMenuClearAll.

The code sample below applies the following modifications:

  • hides the “Not And” operator;
  • removes the “Not Or” operator;
  • disables the “Add Group” operator;
  • renames the “Clear All” operator to “Rename All”.

example1

private void FilterControl1_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
{
    if (e.MenuType == FilterControlMenuType.Group)
    {
        e.Menu.Hide(GroupType.NotAnd);
        e.Menu.Remove(GroupType.NotOr);
        e.Menu.Find(DevExpress.XtraEditors.Controls.StringId.FilterMenuGroupAdd).Enabled = false;
        var clearItem = e.Menu.Find(DevExpress.XtraEditors.Controls.StringId.FilterMenuClearAll);
        if (clearItem != null) clearItem.Caption = "Remove All";
    }
}

Example 2: Group command menu

To customize this menu, use method overloads that accept StringID values.

  • “Add Condition” item: DevExpress.XtraEditors.Controls.StringId.FilterMenuConditionAdd;
  • “Add Group” item: DevExpress.XtraEditors.Controls.StringId.FilterMenuGroupAdd;
  • “Clear All” item: DevExpress.XtraEditors.Controls.StringId.FilterMenuClearAll.

example2

private void FilterControl1_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
{
    if (e.MenuType == FilterControlMenuType.NodeAction)
    {
        e.Menu.Remove(DevExpress.XtraEditors.Controls.StringId.FilterMenuGroupAdd);
        e.Menu.Find(DevExpress.XtraEditors.Controls.StringId.FilterMenuConditionAdd).Enabled = false;
        var clearItem = e.Menu.Find(DevExpress.XtraEditors.Controls.StringId.FilterMenuClearAll);
        if (clearItem != null) clearItem.Caption = "Remove All";
    }
}

Example 3: Field (column) menu

Columns are stored in the FilterControl.FilterColumns collection. You can retrieve columns by their field names. The code below hides the “ID” and “Parent ID” columns from the menu so that users cannot filter data by these fields.

private void FilterControl1_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
{
    FilterControl fc = sender as FilterControl;
    if (e.MenuType == FilterControlMenuType.Column)
    {
        e.Menu.Hide(fc.FilterColumns["ID"]);
        e.Menu.Hide(fc.FilterColumns["ParentID"]);
    }
}

Example 4: Operator menu

To customize standard operator items (“Equals”, “Not null”, “Contains”, etc.), use overloads that accept DevExpress.Data.Filtering.Helpers.ClauseType enumeration values. For unique DateTime operators (“Is same day”, “Is December”, etc.) use DevExpress.Data.Filtering.FunctionOperatorType enumeration values.

The sample below hides the “Is Null” and “Is Not Null” operators, and renames the “Begins With” and “Is Today” operators.

private void FilterControl1_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
{
    if (e.MenuType == FilterControlMenuType.Clause)
    {
        e.Menu.Hide(ClauseType.IsNull);
        e.Menu.Remove(ClauseType.IsNotNull);
        if (e.Menu.Find(ClauseType.BeginsWith) != null)
            e.Menu.Find(ClauseType.BeginsWith).Caption = "Starts With";
        if (e.Menu.Find(FunctionOperatorType.IsOutlookIntervalToday) !=null)
            e.Menu.Find(FunctionOperatorType.IsOutlookIntervalToday).Caption = "Today";
    }
}

Example 5: Operand menu

Same as with column (field) menu, you can access columns through the FilterControl.FilterColumns collection.

To customize items under the “Date and time constants” category use method overloads that accept StringID values:

  • StringId.FilterDateTimeConstantMenuCaption;
  • StringId.FilterCriteriaToStringFunctionLocalDateTimeThisYear;
  • StringId.FilterCriteriaToStringFunctionLocalDateTimeThisMonth;
  • StringId.FilterCriteriaToStringFunctionLocalDateTimeLastWeek;
  • etc.
private void FilterControl1_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
{
    FilterControl fc = sender as FilterControl;
    if (e.MenuType == FilterControlMenuType.ColumnFunctions)
    {
        e.Menu.Hide(fc.FilterColumns["ID"]);
        e.Menu.Find(DevExpress.XtraEditors.Controls.StringId.FilterDateTimeOperatorMenuCaption).Caption = "Unique DateTime constants";
        e.Menu.Find(DevExpress.XtraEditors.Controls.StringId.FilterCriteriaToStringFunctionIsNextMonth).ImageOptions.SvgImage = svgImageCollection1[0];
        e.Menu.Hide(DevExpress.XtraEditors.Controls.StringId.FilterCriteriaToStringFunctionIsNextYear);
    }
}

Example 6: Aggregate node menus

Aggregate columns can be accessed through the FilterControl.FilterColumns collection. To customize aggregate operator items use the DevExpress.Data.Filtering.Aggregate enumeration values.

private void FilterControl1_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
{
    FilterControl fc = sender as FilterControl;
    if (e.MenuType == FilterControlMenuType.Aggregate)
    {
        e.Menu.Find(Aggregate.Avg).Caption = "Average";
        e.Menu.Hide(Aggregate.Exists);
    }

    if (e.MenuType == FilterControlMenuType.AggregateColumn)
    {
        e.Menu.Hide(fc.FilterColumns["InvoiceID"]);
    }
}
See Also