Back to Devexpress

FilterControl.PopupMenuShowing Event

windowsforms-devexpress-dot-xtraeditors-dot-filtercontrol.md

latest15.4 KB
Original Source

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.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("Events")]
public event PopupMenuShowingEventHandler PopupMenuShowing
vb
<DXCategory("Events")>
Public Event PopupMenuShowing As PopupMenuShowingEventHandler

Event Data

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

PropertyDescription
CancelGets or sets a value indicating whether the event should be canceled. Inherited from CancelEventArgs.
CurrentNodeGets the node where the menu is to be displayed.
FocusedElementTypeGets the type of the Filter Control’s element where the menu is to be displayed.
MenuGets the menu that will be invoked.
MenuTypeGets the type of the FilterControl’s menu to be invoked.
PointGets the position where the menu is to be invoked.
RestoreMenuGets 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.

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

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

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

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

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”.

csharp
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";
    }
}
vb
Private Sub FilterControl1_PopupMenuShowing(ByVal sender As Object, ByVal e As PopupMenuShowingEventArgs)
    If e.MenuType = FilterControlMenuType.Group Then
        e.Menu.Hide(GroupType.NotAnd)
        e.Menu.Remove(GroupType.NotOr)
        e.Menu.Find(DevExpress.XtraEditors.Controls.StringId.FilterMenuGroupAdd).Enabled = False
        Dim clearItem = e.Menu.Find(DevExpress.XtraEditors.Controls.StringId.FilterMenuClearAll)
        If clearItem IsNot Nothing Then
            clearItem.Caption = "Remove All"
        End If
    End If
End Sub

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.

csharp
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";
    }
}
vb
Private Sub FilterControl1_PopupMenuShowing(ByVal sender As Object, ByVal e As PopupMenuShowingEventArgs)
    If e.MenuType = FilterControlMenuType.NodeAction Then
        e.Menu.Remove(DevExpress.XtraEditors.Controls.StringId.FilterMenuGroupAdd)
        e.Menu.Find(DevExpress.XtraEditors.Controls.StringId.FilterMenuConditionAdd).Enabled = False
        Dim clearItem = e.Menu.Find(DevExpress.XtraEditors.Controls.StringId.FilterMenuClearAll)
        If clearItem IsNot Nothing Then
            clearItem.Caption = "Remove All"
        End If
    End If
End Sub

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.

csharp
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"]);
    }
}
vb
Private Sub FilterControl1_PopupMenuShowing(ByVal sender As Object, ByVal e As PopupMenuShowingEventArgs)
    If e.MenuType = FilterControlMenuType.NodeAction Then
        e.Menu.Remove(DevExpress.XtraEditors.Controls.StringId.FilterMenuGroupAdd)
        e.Menu.Find(DevExpress.XtraEditors.Controls.StringId.FilterMenuConditionAdd).Enabled = False
        Dim clearItem = e.Menu.Find(DevExpress.XtraEditors.Controls.StringId.FilterMenuClearAll)
        If clearItem IsNot Nothing Then
            clearItem.Caption = "Remove All"
        End If
    End If
End Sub

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.

csharp
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";
    }
}
vb
Private Sub FilterControl1_PopupMenuShowing(ByVal sender As Object, ByVal e As PopupMenuShowingEventArgs)
    If e.MenuType = FilterControlMenuType.Clause Then
        e.Menu.Hide(ClauseType.IsNull)
        e.Menu.Remove(ClauseType.IsNotNull)
        If e.Menu.Find(ClauseType.BeginsWith) IsNot Nothing Then
            e.Menu.Find(ClauseType.BeginsWith).Caption = "Starts With"
        End If
        If e.Menu.Find(FunctionOperatorType.IsOutlookIntervalToday) IsNot Nothing Then
            e.Menu.Find(FunctionOperatorType.IsOutlookIntervalToday).Caption = "Today"
        End If
    End If
End Sub

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.

  • C#

  • VB.NET

csharp
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);
    }
}
vb
Private Sub FilterControl1_PopupMenuShowing(ByVal sender As Object, ByVal e As PopupMenuShowingEventArgs)
    Dim fc As FilterControl = TryCast(sender, FilterControl)
    If e.MenuType = FilterControlMenuType.ColumnFunctions Then
        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)
    End If
End Sub

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.

csharp
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"]);
    }
}
vb
Private Sub FilterControl1_PopupMenuShowing(ByVal sender As Object, ByVal e As PopupMenuShowingEventArgs)
    Dim fc As FilterControl = TryCast(sender, FilterControl)
    If e.MenuType = FilterControlMenuType.Aggregate Then
        e.Menu.Find(Aggregate.Avg).Caption = "Average"
        e.Menu.Hide(Aggregate.Exists)
    End If

    If e.MenuType = FilterControlMenuType.AggregateColumn Then
        e.Menu.Hide(fc.FilterColumns("InvoiceID"))
    End If
End Sub

See Also

FilterControl Class

FilterControl Members

DevExpress.XtraEditors Namespace