Back to Devexpress

ViewFilter.Add(GridColumn, ColumnFilterInfo) Method

windowsforms-devexpress-dot-xtragrid-dot-views-dot-base-dot-viewfilter-dot-add-x28-devexpress-dot-xtragrid-dot-columns-dot-gridcolumn-devexpress-dot-xtragrid-dot-columns-dot-columnfilterinfo-x29.md

latest4.8 KB
Original Source

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.v25.2.dll

NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

csharp
public int Add(
    GridColumn column,
    ColumnFilterInfo filter
)
vb
Public Function Add(
    column As GridColumn,
    filter As ColumnFilterInfo
) As Integer

Parameters

NameTypeDescription
columnGridColumn

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

TypeDescription
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’.

csharp
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Columns;
//...
ColumnView view = gridView1;
view.ActiveFilter.Add(view.Columns["CategoryName"], 
  new ColumnFilterInfo("[CategoryName] Like 'c%'", ""));
vb
Imports DevExpress.XtraGrid.Views.Base
Imports DevExpress.XtraGrid.Columns
'...
Dim view As ColumnView = GridView1
view.ActiveFilter.Add(view.Columns("CategoryName"), 
  New ColumnFilterInfo("[CategoryName] Like 'c%'", ""))

See Also

BeginUpdate()

Filter and Search

ViewFilter Class

ViewFilter Members

DevExpress.XtraGrid.Views.Base Namespace