这里有个例子,自己参考下:using DevExpress.XtraPivotGrid;fieldExtendedPrice.Caption = "Percentage of Orders over $500"; // Enable a custom summary calculation for the Extended Price field. fieldExtendedPrice.SummaryType = DevExpress.Data.PivotGrid.PivotSummaryType.Custom; // Specify the settings used to format values. fieldExtendedPrice.CellFormat.FormatType = DevExpress.Utils.FormatType.Numeric; fieldExtendedPrice.CellFormat.FormatString = "p";int minSum = 500;private void pivotGridControl1_CustomSummary(object sender, PivotGridCustomSummaryEventArgs e) { if(e.DataField != fieldExtendedPrice) return; // A variable which counts the number of orders whose sum exceeds $500. int order500Count = 0; // Get the record set corresponding to the current cell. PivotDrillDownDataSource ds = e.CreateDrillDownDataSource(); // Iterate through the records and count the orders. for(int i = 0; i < ds.RowCount; i++) { PivotDrillDownDataRow row = ds[i]; // Get the order's total sum. decimal orderSum = (decimal)row[fieldExtendedPrice]; if(orderSum >= minSum) order500Count ++; } // Calculate the percentage. if(ds.RowCount > 0) { e.CustomValue = (decimal)order500Count/ds.RowCount; } }
// Enable a custom summary calculation for the Extended Price field.
fieldExtendedPrice.SummaryType = DevExpress.Data.PivotGrid.PivotSummaryType.Custom;
// Specify the settings used to format values.
fieldExtendedPrice.CellFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
fieldExtendedPrice.CellFormat.FormatString = "p";int minSum = 500;private void pivotGridControl1_CustomSummary(object sender,
PivotGridCustomSummaryEventArgs e) {
if(e.DataField != fieldExtendedPrice) return;
// A variable which counts the number of orders whose sum exceeds $500.
int order500Count = 0;
// Get the record set corresponding to the current cell.
PivotDrillDownDataSource ds = e.CreateDrillDownDataSource();
// Iterate through the records and count the orders.
for(int i = 0; i < ds.RowCount; i++) {
PivotDrillDownDataRow row = ds[i];
// Get the order's total sum.
decimal orderSum = (decimal)row[fieldExtendedPrice];
if(orderSum >= minSum) order500Count ++;
}
// Calculate the percentage.
if(ds.RowCount > 0) {
e.CustomValue = (decimal)order500Count/ds.RowCount;
}
}