最近,由于工作需要,深入研究DevExpress Pivot Grid。这款控件功能特别强大,为了方便日后查询,特此记录。
今日完成:在代码中添加未绑定字段,并提供填充数据。
通过 CustomUnboundFieldData 事件,为未绑定字段填充数据。
原型:public event CustomFieldDataEventHandler CustomUnboundFieldData
数据类提供的方法:GetListSourceColumnValue(string columnName),返回控件的基础数据源中已处理行中指定单元格的值。方法原型:public object GetListSourceColumnValue( string columnName ),columnName:指定应获取其值的字段的名称。
官方示例:
public Form1() {
// ...
pivotGridControl1.CustomUnboundFieldData += PivotGridControl1_CustomUnboundFieldData;
PivotGridField fieldExtendedPrice = new PivotGridField() { Caption = "Extended Price", Area = PivotArea.DataArea };
fieldExtendedPrice.UnboundFieldName = "fieldExtendedPrice";
fieldExtendedPrice.UnboundType = DevExpress.Data.UnboundColumnType.Decimal;
pivotGridControl1.Fields.Add(fieldExtendedPrice);
}
private void pivotGridControl1_CustomUnboundFieldData(object sender, CustomFieldDataEventArgs e) {
if (e.Field.UnboundFieldName == "fieldExtendedPrice") {
decimal unitPrice = Convert.ToDecimal(e.GetListSourceColumnValue(fieldUnitPrice.ExpressionFieldName));
int qty = Convert.ToInt32(e.GetListSourceColumnValue(fieldQuantity.ExpressionFieldName));
decimal discount = Convert.ToDecimal(e.GetListSourceColumnValue(fieldDiscount.ExpressionFieldName));
e.Value = unitPrice * qty * (1 - discount);
}
}
属性:ExpressionFieldName,获取未绑定表达式中的字段名称。

357

被折叠的 条评论
为什么被折叠?



