How to: Apply a Filter to a Column
- 2 minutes to read
#Example 1
The following code selects records whose shipping country names start with ‘F’. The required filter is created using a ColumnFilterInfo object. It’s then assigned to the GridColumn.FilterInfo property.
using DevExpress.XtraGrid.Columns;
gridView1.Columns["ShipCountry"].FilterInfo =
new ColumnFilterInfo("[ShipCountry] LIKE 'F%'");
#Example 2
The following code shows how to add a filter condition to a View via its ColumnView.ActiveFilter object. The filter condition selects records whose CategoryName fields start with ‘c’.
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Columns;
//...
ColumnView view = gridView1;
view.ActiveFilter.Add(view.Columns["CategoryName"],
new ColumnFilterInfo("[CategoryName] Like 'c%'", ""));
#Example 3
The following code uses the ColumnView.ActiveFilter property to apply a filter. The filter selects records that contain “Produce” or “Seafood” in the CategoryName column.
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Columns;
//...
ColumnView view = gridView1;
GridColumn colCategory = view.Columns["CategoryName"];
ColumnFilterInfo filter = new ColumnFilterInfo("[CategoryName] = 'Produce' OR [CategoryName] = 'Seafood'", "");
view.ActiveFilter.Add(colCategory, filter);
#Example 4
The following example selects records that contain a null value in the ‘Region’ field.