Back to Devexpress

ColumnView.ShowFilterPopupDate Event

windowsforms-devexpress-dot-xtragrid-dot-views-dot-base-dot-columnview-95b875a6.md

latest5.8 KB
Original Source

ColumnView.ShowFilterPopupDate Event

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

Declaration

csharp
[DXCategory("Behavior")]
public event FilterPopupDateEventHandler ShowFilterPopupDate
vb
<DXCategory("Behavior")>
Public Event ShowFilterPopupDate As FilterPopupDateEventHandler

Event Data

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

PropertyDescription
ColumnGets the grid column being processed. Inherited from FilterPopupEventArgs.
ListGets 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 filter 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:

csharp
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));
}
vb
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

FilterPopupMode

ColumnView Class

ColumnView Members

DevExpress.XtraGrid.Views.Base Namespace