Back to Devexpress

How to: Perform Custom Filtering When the (Custom) Item is Selected in the Filter Dropdown

windowsforms-3011-controls-and-libraries-data-grid-examples-filtering-how-to-perform-custom-filtering-when-the-custom-item-is-selected-in-the-filter-dropdown.md

latest1.7 KB
Original Source

How to: Perform Custom Filtering When the (Custom) Item is Selected in the Filter Dropdown

  • Nov 13, 2018

The following sample code implements custom filtering and disables the Custom Filter Dialog dialog for the UnitPrice column.

When a (Custom) item is selected in the filter dropdown a custom filter criteria will be created and applied to the View. These criteria select records which contain values less than 10 or greater than 30 in the “UnitPrice” column.

csharp
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Columns;

private void gridView1_CustomFilterDialog(object sender, CustomFilterDialogEventArgs e) {
      if (e.Column.FieldName == "UnitPrice") {
         e.FilterInfo = new ColumnFilterInfo(
           ColumnFilterType.Custom, null, "[UnitPrice] < 10 Or [UnitPrice] > 30", 
           "[Unit Price] < '10' Or [Unit Price] > '30'");
         e.Handled = true;
      }
}
vb
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraGrid.Columns

Private Sub GridView1_CustomFilterDialog(ByVal sender As System.Object, _
  ByVal e As CustomFilterDialogEventArgs) Handles GridView1.CustomFilterDialog
      If e.Column.FieldName = "UnitPrice" Then
         e.FilterInfo = New ColumnFilterInfo( _
           ColumnFilterType.Custom, Nothing, "[UnitPrice] < 10 Or [UnitPrice] > 30", _
           "[Unit Price] < '10' Or [Unit Price] > '30'")
         e.Handled = True
      End If
End Sub