[size=1em]1
[size=1em]2
[size=1em]3
[size=1em]4
[size=1em]5
[size=1em]6
[size=1em]7
[size=1em]8
[size=1em]9
[size=1em]10
[size=1em]11
[size=1em]12
[size=1em]13
[size=1em]14
[size=1em]15
[size=1em]16
[size=1em]17
[size=1em]18
[size=1em]19
[size=1em]20
[size=1em]21
[size=1em]22
[size=1em]23
[size=1em]24
[size=1em]25
[size=1em]26
[size=1em]27
[size=1em]28
[size=1em]29
[size=1em]30
| [size=1em][size=1em]using DevExpress.XtraPivotGrid;
[size=1em]fieldExtendedPrice.Caption = "Percentage of Orders over $500";
[size=1em]// Enable a custom summary calculation for the Extended Price field.
[size=1em]fieldExtendedPrice.SummaryType = DevExpress.Data.PivotGrid.PivotSummaryType.Custom;
[size=1em]// Specify the settings used to format values.
[size=1em]fieldExtendedPrice.CellFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
[size=1em]fieldExtendedPrice.CellFormat.FormatString = "p";
[size=1em]int minSum = 500;
[size=1em]private void pivotGridControl1_CustomSummary(object sender,
[size=1em] PivotGridCustomSummaryEventArgs e) {
[size=1em] if(e.DataField != fieldExtendedPrice) return;
[size=1em] // A variable which counts the number of orders whose sum exceeds $500.
[size=1em] int order500Count = 0;
[size=1em] // Get the record set corresponding to the current cell.
[size=1em] PivotDrillDownDataSource ds = e.CreateDrillDownDataSource();
[size=1em] // Iterate through the records and count the orders.
[size=1em] for(int i = 0; i < ds.RowCount; i++) {
[size=1em] PivotDrillDownDataRow row = ds;
[size=1em] // Get the order's total sum.
[size=1em] decimal orderSum = (decimal)row[fieldExtendedPrice];
[size=1em] if(orderSum >= minSum) order500Count ++;
[size=1em] }
[size=1em] // Calculate the percentage.
[size=1em] if(ds.RowCount > 0) {
[size=1em] e.CustomValue = (decimal)order500Count/ds.RowCount;
[size=1em] }
[size=1em]}
|