ViewFilter.Add(GridColumn, ColumnFilterInfo) Method
Adds the specified filter criteria to the collection and thus applies them to a View.
Namespace: DevExpress.XtraGrid.Views.Base
Assembly: DevExpress.XtraGrid.v24.2.dll
Declaration
Parameters
Name | Type | Description |
---|---|---|
column | GridColumn | A GridColumn object representing the column which the specified filter condition is applied to. |
filter | ColumnFilterInfo | A ColumnFilterInfo object specifying the filter condition applied to the column. |
Returns
Type | Description |
---|---|
Int32 | A zero-based integer specifying the position at which the filter condition was added amongst the other filter conditions within the current collection. -1 if the given filter condition’s functionality is disabled (its ColumnFilterInfo.Kind property is set to ColumnFilterType.None). |
Remarks
The Add method can be used to add specific filter criteria to a View.
The filter condition represented by the filter parameter will be associated with the specified column. If the current ViewFilter object already contains a filter condition associated with the specified column, the new filter condition will replace the previous one.
Filter conditions within the ViewFilter collection are represented by DevExpress.XtraGrid.Views.Base.ViewColumnFilterInfo objects. ViewColumnFilterInfo merely associates a grid column with a ColumnFilterInfo object.
The Add method creates a new ViewColumnFilterInfo object which refers to the specified column and ColumnFilterInfo object and adds it to the collection. The index of the new element is returned.
Calling the Add method is equivalent to assigning filter criteria to a column via its GridColumn.FilterInfo property.
Note that the ColumnFilterInfo object can define a filter condition involving several columns. For more details on constructing filter conditions, see the Filter and Search topic.
Example
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%'", ""));