Represents a collection of filter conditions applied to a View.
[ListBindable(false)] public class ViewFilter : CollectionBase, ICloneable
<ListBindable(False)> Public Class ViewFilter Inherits CollectionBase Implements ICloneable
Related API Members
The following members accept/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 or ViewFilter.AddRange 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 shows how to add a filter condition to a View via its ColumnView.ActiveFilter object. The filter condition selects records which contain the values "Produce" or "Seafood" in the CategoryName column.
using DevExpress.XtraGrid.Views.Base; using DevExpress.XtraGrid.Columns; //... ColumnView view = gridView1; ViewColumnFilterInfo viewFilterInfo = new ViewColumnFilterInfo(view.Columns["CategoryName"], new ColumnFilterInfo("[CategoryName] = 'Produce' OR [CategoryName] = 'Seafood'", "")); view.ActiveFilter.Add(viewFilterInfo);