Skip to main content

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

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.

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;