Back to Devexpress

How to: Apply a Custom Text Filter

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

latest2.4 KB
Original Source

How to: Apply a Custom Text Filter

  • Apr 01, 2021
  • 2 minutes to read

This example demonstrates how to specify the custom compound filter criteria to filter text values 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 "Product" column that contain "Gi" and include empty cells.
AutoFilterColumn products = worksheet.AutoFilter.Columns[1];
products.ApplyCustomFilter("*Gi*", FilterComparisonOperator.Equal, FilterValue.FilterByBlank, FilterComparisonOperator.Equal, false);
vb
' Enable filtering for the specified cell range.
Dim range As CellRange = worksheet("B2:E23")
worksheet.AutoFilter.Apply(range)

' Filter values in the "Product" column that contain "Gi" and include empty cells.
Dim products As AutoFilterColumn = worksheet.AutoFilter.Columns(1)
products.ApplyCustomFilter("*Gi*", FilterComparisonOperator.Equal, FilterValue.FilterByBlank, FilterComparisonOperator.Equal, False)