原創|其它|編輯:郝浩|2012-10-22 11:51:05.000|閱讀 2005 次
概述:DevExpress實現自定義求和的效果圖及事例代碼
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
自定義求和的效果圖如下:
C#
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; } }
VB
Imports 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" Dim minSum As Integer = 500 Private Sub PivotGridControl1_CustomSummary(ByVal sender As Object, _ ByVal e As PivotGridCustomSummaryEventArgs) Handles PivotGridControl1.CustomSummary If Not e.DataField Is fieldExtendedPrice Then Return ' A variable which counts the number of orders whose sum exceeds $500. Dim order500Count As Integer = 0 ' Get the record set corresponding to the current cell. Dim ds As PivotDrillDownDataSource = e.CreateDrillDownDataSource() ' Iterate through the records and count the orders. Dim i As Integer For i = 0 To ds.RowCount - 1 Dim row As PivotDrillDownDataRow = ds(i) ' Get the order's total sum. Dim orderSum As Decimal = row(fieldExtendedPrice) If orderSum >= minSum Then order500Count = order500Count + 1 Next ' Calculate the percentage. If ds.RowCount > 0 Then e.CustomValue = order500Count / ds.RowCount End If End Sub
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網