Log In
[Expand]General Information
[Collapse]WinForms Controls
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Collapse]Data Grid
   [Expand]Getting Started
   [Expand]Binding to Data
   [Expand]Grid View
   [Expand]View Technology
   [Expand]Data Editing
   [Collapse]Filtering and Locating Rows
     [Expand]Filter Dropdowns
      Filtering Overview
      Filter Settings
      MRU Filters
      Automatic Filtering Row
      Filter Editor
      Custom Filter Dialog
      Filtering in Code
     Locating Rows in Code
     Incremental Search
     Searching via Find Panel
     Tutorial: Incremental Search
     Tutorial: Search/Find Panel
   [Expand]Focus and Selection Handling
   [Expand]Processing Rows
   [Expand]Formatting Cell Values
   [Expand]Master-Detail Relationships
   [Expand]Asynchronous Image Load
   [Expand]Export and Printing
   [Expand]Appearance and Conditional Formatting
   [Expand]Batch Modifications
   [Expand]Hit Information
   [Expand]Popup Menus
   [Expand]Saving and Restoring Layouts
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]End-User Capabilities
    Included Components
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Map Control
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]PDF Viewer
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Report Server
[Expand]eXpressApp Framework
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Custom Filter Dialog

Grid Control provides the Custom Filter Dialog with which to specify filter criteria for a column at runtime. The end-user can access the dialog by selecting a (Custom) item from the filter dropdown list. This document shows you how to implement special behavior when a (Custom) item is selected. For instance, you can provide custom filtering, supply another filter dialog or customize an existing one. For general information on filtering in XtraGrid, see the Filtering Overview section. The Filter Dropdowns document describes how you can add or delete items from a filter dropdown list.

Expanded Online Video

In this video, you will learn how to use the MS Excel-style Filter Editor available to end-users by default, and how to invoke and customize this editor in code.

Expanded Custom Filter Dialog

The Custom Filter Dialog allows you to set filter criteria for a column. Filter criteria can consist of one or two filter conditions combined by AND or OR Boolean operators. Grid Control provides two types of Custom Filter Dialogs. You can switch between them via the ColumnViewOptionsFilter.UseNewCustomFilterDialog property.

If the property is set to false (the default value), the grid displays the default Custom Filter Dialog when you select the (Custom) item from the filter dropdown list. This allows you to set filter criteria that compare values of the current column with specified values.

The combo box editors displayed to the left allow you to select comparison operators for filter conditions. The values with which to compare can be entered via the editors displayed to the right.

If the ColumnViewOptionsFilter.UseNewCustomFilterDialog property is set to true, the advanced Custom Filter Dialog is used instead. This extends the functionality of the default dialog by adding the ability to compare current column values with values of another column.

If the Field check box is cleared, the dialog acts like a default dialog. If the Field option is checked, editors displayed to the right allow you to select columns with which to compare.

To implement special behavior when a (Custom) filter item is selected, you can handle the ColumnView.CustomFilterDialog event. For instance, you can prevent the display, or customize the standard Custom Filter Dialog, invoke your own filter dialog, or automatically apply filter criteria to a column.

The ColumnView.ShowCustomFilterDialog method allows you to manually activate the custom filter dialog for a specific column.

Expanded Applying Custom Filter Criteria

Suppose you want to apply particular filter criteria automatically to a column when the (Custom) item is selected. For this purpose, you can assign the filter criteria to the event's CustomFilterDialogEventArgs.FilterInfo parameter. You should also set the CustomFilterDialogEventArgs.Handled property to true. This prevents the standard filter dialog from opening after your event handler is performed.

In the following example, when the (Custom) item for the OrderDate, RequiredDate or ShippedDate columns is selected, the "Column = TODAY" filter is applied to the corresponding column. For information on creating filter conditions via code, see the Filtering Overview document.

If you need to customize the text for the (Custom) item in the filter dropdown list, you can handle the ColumnView.ShowFilterPopupListBox event. In the current example, the "(Custom)" text is replaced with "(TODAY)":
Refer to the Filter Dropdowns section for information on filter dropdown lists. This provides examples of adding and deleting filter items and controlling filter criteria when specific items are selected.

Expanded Customizing the Standard Filter Dialog

You can handle the ColumnView.CustomFilterDialog event to display your own or the standard filter dialog. The default and advanced filter dialogs are represented by the DevExpress.XtraGrid.Filter.FilterCustomDialog and DevExpress.XtraGrid.Filter.FilterCustomDialog2 classes respectively. These are derived from the System.Windows.Forms.Form class, so you can use their members to customize a window (specify the window's caption, position, access controls residing within the dialog, etc.).

As stated above, the advanced Custom Filter Dialog allows for the comparing of values of the current column with values of another column when the Field option is checked. The captions of the columns with which to compare are displayed in the value combo box editors. When you create an advanced Custom Filter Dialog via code, you can supply the collection of columns with which to compare. Also, you can specify whether only visible column captions should be available or whether all the columns from the collection should be available.

The following example shows how to invoke the advanced Custom Filter Dialog when the (Custom) filter item is selected for the 'RequiredDate' and 'ShippedDate' columns. In the dialog's constructor, the first parameter refers to the column, for which the filter criteria should be set. The second parameter specifies the collection of columns to display in the dialog's value combo boxes. The third parameter specifies that all columns from the collection should be available via value combo boxes.

After creating the dialog, its Field check boxes are set to checked. The Field check boxes are accessed in the setFieldCheckBox method by traversing all dialog controls.

After the dialog is closed, the new filter criteria representing the user's choice is already set via the column's GridColumn.FilterInfo property. In order to prevent overriding these criteria, the CustomFilterDialogEventArgs.FilterInfo property must be set to null (Nothing in Visual Basic). Otherwise, this property value will be assigned to the column's GridColumn.FilterInfo property. In order to prevent the standard filter dialog from displaying after your event handler is performed, the CustomFilterDialogEventArgs.Handled parameter must be set to false.

The image below illustrates the customized filter dialog displayed for the 'RequiredDate' column. Note that the value combo box does not include the caption of the column for which the dialog is invoked, even if it is contained in the supplied column collection.

Expanded See Also

How would you rate this topic?​​​​​​​