FlexGrid, not only provides built-in filters such as Column filter, Value filter, and Condition Filter but also lets you create your own custom filter. The built-in filters are provided through AllowFiltering property of Column class which lets you set the type of filter to be applied on a particular column. On the other hand, the custom filters make use of the IC1ColumnFilter interface and the IC1ColumnFilterEditor interface. This topic discusses the implementation of built-in and custom filters in detail.
Column filter is the default filter that is applied to all the columns automatically when AllowFiltering property of the grid is set to true. The ColumnFilter is a combination of ValueFilter and ConditionFilter (discussed below) and gives user an option to choose either of them at runtime. While working with code, you can use its ValueFilter and ConditionFilter properties to access the two types of filters. The filter also provides Apply method to apply filter to a value and Reset method to reset the filter and hence making it inactive.
Use the below code to apply column filter on ProductName column of the WinForms FlexGrid.
Value filter refers to the value based filter which gets enabled on setting the AllowFiltering property of column to ByValue. The ValueFilter provides the dropdown list of all values with checkbox which lets the user select the values which are to be displayed in the output. These values can be get or set through the ShowValues property. You can also set a limit on number of values to be displayed in the dropdown list by setting the ValuesLimit property. Just like column filter, value filter also provides Apply method to apply filter to a value and Reset method to reset the filter.
Below code shows how to apply ValueFilter on a column of the WinForms FlexGrid.
Condition filter refers to a filter based on one or two logical conditions which can be enabled by setting the AllowFiltering property to ByCondition. The ConditionFilter gives user an option to set the condition/s through Condition1 and Condition2 properties which can be combined using AND/OR operator by setting the AndConditions property to filter the records. Similar to other filters, this class also provides Apply and Reset method.
Below code demonstrates how to apply a ConditionFilter on a WinForms FlexGrid column.
The abovementioned filters provide you enough flexibility to implement most common filtering scenarios efficiently. In addition, custom filter option also lets you create your own filter to meet any other specialized requirements of your application. To create a custom filter, you need to create a filter class that implements the IC1ColumnFilter interface, and an editor class that implements the IC1ColumnFilterEditor interface. By default, the default filters are also displayed along with the custom filter. However, you can choose to hide these default filters by setting ValueFilterEnabled and ConditionFilterEnabled properties to false. Additionally, you can easily export and import filter definitions using WriteXml and ReadXml methods, respectively. For proper implementation of custom column filters in FlexGrid, see Custom Column Filters.