windowsforms-devexpress-dot-xtraeditors-dot-filtercontrol.md
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
[DXCategory("Events")]
public event PopupMenuShowingEventHandler PopupMenuShowing
<DXCategory("Events")>
Public Event PopupMenuShowing As PopupMenuShowingEventHandler
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. |
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.
Use the following methods to find and customize menu items:
To forcibly close a menu, set the e.Cancel parameter to true.
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:
The code sample below applies the following modifications:
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";
}
}
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
To customize this menu, use method overloads that accept StringID values.
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";
}
}
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
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"]);
}
}
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
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";
}
}
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
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);
}
}
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
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"]);
}
}
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