原創|其它|編輯:郝浩|2012-10-25 10:09:18.000|閱讀 690 次
概述:本文通過具體事例步驟講解如何添加未綁定的字段到XtraPivotGrid控件。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
在本例中,將為你展示在DevEXpress中如何添加未綁定的字段到XtraPivotGrid控件,我們添加的字段為訂單總和。
首先,創建一個名為Total Sum的字段。
其次,將字段 PivotGridFieldBase.UnboundType 屬性設為UnboundColumnType.Decimal。
最后,最后,用數據填充字段。
VB
Imports DevExpress.XtraPivotGrid ' Create a field with the specified field name. Dim unboundField As PivotGridField = pivotGridControl1.Fields.Add("Total Sum", PivotArea.DataArea) ' Specify the type of the field's values. unboundField.UnboundType = DevExpress.Data.UnboundColumnType.Decimal ' Populates the unbound field. Private Sub pivotGridControl1_CustomUnboundFieldData(ByVal sender As System.Object, _ ByVal e As CustomFieldDataEventArgs) If (e.Field.FieldName = "Total Sum") Then Dim unitPrice As Decimal = Convert.ToDecimal(e.GetListSourceColumnValue("UnitPrice")) Dim qty As Int32 = Convert.ToInt32(e.GetListSourceColumnValue("Quantity")) Dim discount As Decimal = Convert.ToDecimal(e.GetListSourceColumnValue("Discount")) e.Value = unitPrice * qty * (1 - discount) End If End Sub
C#
using DevExpress.XtraPivotGrid; // Create a field with the specified field name. PivotGridField unboundField = pivotGridControl1.Fields.Add("Total Sum", PivotArea.DataArea); // Specify the type of the field's values. unboundField.UnboundType = DevExpress.Data.UnboundColumnType.Decimal; // Populates the unbound field. private void pivotGridControl1_CustomUnboundFieldData(object sender, CustomFieldDataEventArgs e) { if(e.Field.FieldName == "Total Sum") { decimal unitPrice = Convert.ToDecimal(e.GetListSourceColumnValue("UnitPrice")); int qty = Convert.ToInt32(e.GetListSourceColumnValue("Quantity")); decimal discount = Convert.ToDecimal(e.GetListSourceColumnValue("Discount")); e.Value = unitPrice*qty*(1-discount); } }
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網