Back to Devexpress

How to: Reapply a Filter

officefileapi-113768-spreadsheet-document-api-examples-filter-data-how-to-reapply-a-filter.md

latest1.6 KB
Original Source

How to: Reapply a Filter

  • Sep 19, 2023

The example below demonstrates how to use the AutoFilterBase.ReApply method of the SheetAutoFilter object to reapply a filter after the data in the filtered range has been changed.

View Example

csharp
Worksheet worksheet = workbook.Worksheets["Regional sales"];
workbook.Worksheets.ActiveWorksheet = worksheet;

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

// Filter values in the "Sales" column that are greater than 5000$.
worksheet.AutoFilter.Columns[2].ApplyCustomFilter(5000, FilterComparisonOperator.GreaterThan);

// Change the data and reapply the filter.
worksheet["D3"].Value = 5000;
worksheet.AutoFilter.ReApply();
vb
Dim worksheet As Worksheet = workbook.Worksheets("Regional sales")
workbook.Worksheets.ActiveWorksheet = worksheet

' 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 greater than 5000$.
worksheet.AutoFilter.Columns(2).ApplyCustomFilter(5000, FilterComparisonOperator.GreaterThan)

' Change the data and reapply the filter.
worksheet("D3").Value = 5000
worksheet.AutoFilter.ReApply()