彩票走势图

DevExpress如何实现自定义求和

原创|其它|编辑:郝浩|2012-10-22 11:51:05.000|阅读 2005 次

概述:DevExpress实现自定义求和的效果图及事例代码

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

自定义求和的效果图如下:

DevExpress如何实现自定义求和

代码如下:

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


标签:DevExpress

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn

文章转载自:慧都控件网

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP