How to: Apply Summary Filter

  • 3 minutes to read

The following example shows how to apply a summary filter to PivotGridControl data that belongs to a particular aggregation level.

In this example, Pivot Grid Control displays product sales by country. The summary filter is applied to country totals calculated for individual products, so that only values that fall into the range from 500 to 2500 are included.

The range of included values is specified using the PivotSummaryFilter.StartValue and PivotSummaryFilter.EndValue properties. To enable filtering only for the selected aggregation level, the PivotSummaryFilter.Mode property is set to PivotSummaryFilterMode.SpecificLevel. To identify this level, the PivotSummaryFilter.RowField and PivotSummaryFilter.ColumnField properties are set to fieldProductName and fieldCountry respectively.

using System;
using System.Windows.Forms;
using DevExpress.XtraPivotGrid;

namespace XtraPivotGrid_ApplySummaryFilter {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e) {

            // Binds the pivot grid to data.
            this.salesPersonTableAdapter.Fill(this.nwindDataSet.SalesPerson);

            // Locks the control to prevent excessive updates when multiple properties are modified.
            pivotGridControl1.BeginUpdate();
            try {

                // Sets the minimum summary value to be displayed.
                fieldExtendedPrice.SummaryFilter.StartValue = 500;

                // Sets the maximum summary value to be displayed.
                fieldExtendedPrice.SummaryFilter.EndValue = 2500;

                // Specifies that summary filtering should be applied
                // to a particular aggregation level.
                fieldExtendedPrice.SummaryFilter.Mode = PivotSummaryFilterMode.SpecificLevel;

                // Sets the row used to identify an aggregation level
                // to which the filtering is applied.
                fieldExtendedPrice.SummaryFilter.RowField = fieldProductName;

                // Sets the column used to identify an aggregation level
                // to which the filtering is applied.
                fieldExtendedPrice.SummaryFilter.ColumnField = fieldCountry;
            }
            finally {

                // Unlocks the control.
                pivotGridControl1.EndUpdate();
            }
        }
    }
}