Back to Devexpress

How to: Apply a Custom Number Filter

wpf-18133-controls-and-libraries-spreadsheet-examples-filter-data-how-to-apply-a-custom-number-filter.md

latest2.3 KB
Original Source

How to: Apply a Custom Number Filter

  • Jun 07, 2019
  • 2 minutes to read

This example demonstrates how to specify the custom compound filter criteria to filter numbers in a column.

  1. Turn on the filtering functionality for the required range, as described in the How to: Enable Filtering example.
  2. Use the AutoFilterBase.Columns property of the SheetAutoFilter object to get a collection of columns in the filtered range (the AutoFilterColumnCollection object). Each column in the collection is defined by the AutoFilterColumn object, which provides basic methods for data filtering. To filter data in a particular column, get access to this column by its index in the AutoFilterColumnCollection collection.
  3. To apply a custom complex filter, call the AutoFilterColumn.ApplyCustomFilter method overload with five parameters.

View Example

csharp
// Enable filtering for the specified cell range.
CellRange range = worksheet["B2:E23"];
worksheet.AutoFilter.Apply(range);

// Filter values in the "Sales" column that are in a range from 5000$ to 8000$.
AutoFilterColumn sales = worksheet.AutoFilter.Columns[2];
sales.ApplyCustomFilter(5000, FilterComparisonOperator.GreaterThanOrEqual, 8000, FilterComparisonOperator.LessThanOrEqual, true);
vb
' Enable filtering for the specified cell range.
Dim range As CellRange = worksheet("B2:E23")
worksheet.AutoFilter.Apply(range)

' Filter values in the "Sales" column that are in a range from 5000$ to 8000$.
Dim sales As AutoFilterColumn = worksheet.AutoFilter.Columns(2)
sales.ApplyCustomFilter(5000, FilterComparisonOperator.GreaterThanOrEqual, 8000, FilterComparisonOperator.LessThanOrEqual, True)