Skip to main content
A newer version of this page is available. .

How to: Apply a Filter to a View

Example 1

This example demonstrates how to assign a filter to a View using the ColumnView.ActiveFilterString property.

gridView1.ActiveFilterString = "([ProductID] = 1 OR [ProductID] = 3 " + 
  "OR [ProductID] > 10) AND [Discount] = 0";

Example 2

The following code demonstrates how to create filter criteria and assign them to a Grid View via the ColumnView.ActiveFilterCriteria property. The criteria is created using the operators defined in the DevExpress.Data.Filtering namespace (the GroupOperator and BinaryOperator classes). The created criteria represent the filter expression: “[Extension] = ‘.gif’ OR [Extension] = ‘.png’”.

using DevExpress.Data.Filtering;

CriteriaOperator expr1 = new BinaryOperator("Extension", ".gif");
CriteriaOperator expr2 = new BinaryOperator("Extension", ".png");
gridView1.ActiveFilterCriteria = GroupOperator.Or(new CriteriaOperator[] { expr1, expr2 });