vcl-157001-expresspivotgrid-concepts-how-to-apply-a-filter-to-a-field.md
The following code snippet demonstrates how to filter the PivotGridPurchaseDate field which contains date-time values, by two dates: 2/1/2002 and 2/2/2002.
PivotGrid.BeginUpdate;
with PivotGridPurchaseDate.Filter do
begin
with Values do
begin
// Clears the field's filter condition.
Clear;
// Adds two dates into the filter condition.
Add(EncodeDate(2002, 2, 1));
Add(EncodeDate(2002, 2, 2));
end;
// Specifies the filter type as inclusive.
FilterType := ftIncluded;
end;
PivotGrid.EndUpdate;
PivotGrid->BeginUpdate();
try {
TcxPivotGridFieldFilter *AFilter = PivotGridPurchaseDate->Filter;
// Clears the field's filter condition.
AFilter->Values->Clear();
// Adds two dates into the filter condition.
AFilter->Values->Add(EncodeDate(2002, 2, 1));
AFilter->Values->Add(EncodeDate(2002, 2, 2));
// Specifies the filter type as inclusive.
AFilter->FilterType = ftIncluded;
}
__finally {
PivotGrid->EndUpdate();
}
As a result, the pivot grid displays only the records that correspond to the created filter.