Skip to main content

ColumnView.ShowFilterPopupDate Event

Allows you to customize the filter dropdown for date-time columns.

Namespace: DevExpress.XtraGrid.Views.Base

Assembly: DevExpress.XtraGrid.v24.1.dll

NuGet Packages: DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

[DXCategory("Behavior")]
public event FilterPopupDateEventHandler ShowFilterPopupDate

Event Data

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.

Remarks

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:

  • Implement filter criteria by creating a CriteriaOperator object
  • Create a new filter item (a DevExpress.XtraEditors.FilterDateElement object). Initialize the item’s caption, and provide the created CriteriaOperator when calling the item’s constructor. You can also assign a tooltip to the item.
  • Add the item to the event’s List parameter

Note

If you handle events from the list below, Data Grid switches from Excel-style filters to classic filtering menus. In this case, set the GridColumn.OptionsFilter.FilterPopupMode property to Excel to use Excel-style filters.

Example

The 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:

ShowFilterPopupDate_ex

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));
}
See Also