Back to Devexpress

How to: Enable Filtering

windowsforms-18033-controls-and-libraries-spreadsheet-examples-filter-data-how-to-enable-filtering.md

latest3.6 KB
Original Source

How to: Enable Filtering

  • Apr 15, 2025
  • 2 minutes to read

The examples below demonstrate how to enable a filtering functionality in the SpreadsheetControl.

Watch Video

Filter a Worksheet Range

To activate filtering for a specific range in a worksheet, do the following.

  1. Use the Worksheet.AutoFilter property to get access to the SheetAutoFilter object. This object inherits the AutoFilterBase interface, which provides basic methods and properties used to apply, clear or disable a filter and sort values in the filtered range.
  2. Call the SheetAutoFilter.Apply method to enable filtering. Pass the CellRange object you wish to filter as a parameter.

View Example

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

Once the filtering functionality is activated, a drop-down arrow appears on the right side of each column header in the filtered range. An end-user can click the arrow of the desired column and select the required filter options in the AutoFilter drop-down menu.

Filter a Table

The default behavior is when you create a table in a worksheet, it already has the AutoFilter functionality turned on. In this case, to filter data in the table columns you need to get access to the required table in the worksheet’s TableCollection and then use the Table.AutoFilter property to return the TableAutoFilter object. This object inherits the AutoFilterBase base interface, which provides common methods and properties used to apply, clear or disable a table filter and sort values in the table columns in the same manner as it can be done for a worksheet range.

csharp
// Access a table.
Table table = worksheet.Tables[0];
// Filter values in the "Amount" column that are greater than 75$.
table.AutoFilter.Columns[4].ApplyCustomFilter(75, FilterComparisonOperator.GreaterThanOrEqual);
vb
' Access a table.
Dim table As Table = worksheet.Tables(0)
' Filter values in the "Amount" column that are greater than 75$.
table.AutoFilter.Columns(4).ApplyCustomFilter(75, FilterComparisonOperator.GreaterThanOrEqual)

Tip

If you disabled the filtering functionality for a particular table, you can reactivate it by using the TableAutoFilter.Apply method.