Represents a collection of filter conditions applied to a View.
NuGet Package: DevExpress.Win.Grid
[ListBindable(false)] public class ViewFilter : CollectionBase, ICloneable
<ListBindable(False)> Public Class ViewFilter Inherits CollectionBase Implements ICloneable
Related API Members
The following members return ViewFilter objects:
Each ColumnView descendant provides the ColumnView.ActiveFilter property of the ViewFilter type and this represents a collection of filter conditions for the View. Use this collection to apply filter conditions to the View programmatically.
All the conditions within the collection are concatenated by the Boolean AND operator to constitute the overall filter criteria used to filter data. Each filter condition in the collection is represented by a DevExpress.XtraGrid.Views.Base.ViewColumnFilterInfo object which contains two public properties:
- ViewColumnFilterInfo.Column of the GridColumn type. This defines the column which the associated filter condition is applied to.
- ViewColumnFilterInfo.Filter of the ColumnFilterInfo type. This specifies the filter condition itself. For more information on constructing filter conditions, see the Advanced Filter and Search Concepts topic.
Filter conditions from the ViewFilter collection will be used to filter data only if the ColumnView.ActiveFilterEnabled property is set to true. This property can be set to false to temporarily disable filtering. This does not remove filter conditions from the collection. To completely remove all the filter conditions the ViewFilter‘s Clear or ColumnView.ClearColumnsFilter method can be called.
To apply filtering to a view, one of the following methods can be used:
- call the ViewFilter.Add method with the filter conditions specified.
- assign a filter condition (ColumnFilterInfo object) to the GridColumn.FilterInfo property. This will add a corresponding element to the current collection.
For more information refer to the Filter and Search document.
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);