windowsforms-devexpress-dot-xtragrid-dot-views-dot-base-dot-columnview-95b875a6.md
Allows you to customize the filter dropdown for date-time columns.
Namespace : DevExpress.XtraGrid.Views.Base
Assembly : DevExpress.XtraGrid.v25.2.dll
NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation
[DXCategory("Behavior")]
public event FilterPopupDateEventHandler ShowFilterPopupDate
<DXCategory("Behavior")>
Public Event ShowFilterPopupDate As FilterPopupDateEventHandler
The ShowFilterPopupDate event's data class is FilterPopupDateEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| Column | Gets the grid column being processed. Inherited from FilterPopupEventArgs. |
| List | Gets the list of filter items represented as check boxes within the filter dropdown window. |
For a date-time column, the filter dropdown contains an embedded calendar to select date ranges. In addition, this filter dropdown displays check boxes below the calendar allowing an end-user to select common date intervals. The set of available check boxes is specified by the OptionsColumnFilter.FilterPopupMode property. The ShowFilterPopupDate event allows this filter dropdown to be customized. For instance, you can remove particular check boxes or add custom filter items that will be represented as new check boxes.
To add a custom filter item, do the following:
Note
If you handle events from the list below, Data Grid switches from Excel-style filters to classic filter menus. In this case, set the GridColumn.OptionsFilter.FilterPopupMode property to Excel to use Excel-style filters.
ColumnView.ShowFilterPopupDateThe following example shows how to add a custom filter item to the filter dropdown for a Date column.
The ColumnView.ShowFilterPopupDate event is handled, and a new filter item is added to the event’s List parameter. The filter item, when checked by an end-user, will select the records that refer to last year:
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.Data.Filtering;
private void gridView1_ShowFilterPopupDate(object sender, FilterPopupDateEventArgs e) {
if(e.Column.FieldName != "Date") return;
e.List.Clear();
DateTime firstDayOfThisYear = new DateTime(DateTime.Today.Year, 1, 1);
DateTime firstDayOfLastYear = firstDayOfThisYear.AddYears(-1);
CriteriaOperator lastYear = new BinaryOperator(
e.Column.FieldName, firstDayOfLastYear, BinaryOperatorType.GreaterOrEqual);
CriteriaOperator thisYear = new BinaryOperator(
e.Column.FieldName, firstDayOfThisYear, BinaryOperatorType.Less);
CriteriaOperator crit = new GroupOperator(GroupOperatorType.And, lastYear, thisYear);
e.List.Add(new DevExpress.XtraEditors.FilterDateElement("Last Year", "", crit));
}
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.Data.Filtering
Private Sub GridView1_ShowFilterPopupDate(ByVal sender As System.Object, _
ByVal e As FilterPopupDateEventArgs) Handles GridView1.ShowFilterPopupDate
If e.Column.FieldName <> "Date" Then Return
e.List.Clear()
Dim firstDayOfThisYear As DateTime = New DateTime(DateTime.Today.Year, 1, 1)
Dim firstDayOfLastYear As DateTime = firstDayOfThisYear.AddYears(-1)
Dim lastYear As CriteriaOperator = New BinaryOperator( _
e.Column.FieldName, firstDayOfLastYear, BinaryOperatorType.GreaterOrEqual)
Dim thisYear As CriteriaOperator = New BinaryOperator( _
e.Column.FieldName, firstDayOfThisYear, BinaryOperatorType.Less)
Dim crit As CriteriaOperator = New GroupOperator( _
GroupOperatorType.And, lastYear, thisYear)
e.List.Add(New DevExpress.XtraEditors.FilterDateElement("Last Year", "", crit))
End Sub
See Also