The event handler receives an argument of type PivotCustomFieldDataEventArgs containing data related to this event.
The following
PivotCustomFieldDataEventArgs properties provide information specific to this event.
Property |
Description |
Field |
Gets the unbound field currently being processed. |
ListSourceRowIndex |
Gets the current row's index in the data source. |
ThreadSafeField |
Gets the unbound field currently being processed. Provides read-only access to field settings. |
Value |
Gets or sets the value of the cell currently being processed. |
Unbound fields are not bound to any field in the data source. In most instances, data for unbound fields is obtained from a custom data source or is calculated based upon the values of bound fields. To provide data for unbound fields, you can specify an expression (formula) used to evaluate values for this field using the PivotGridField.UnboundExpression property or handle the CustomUnboundFieldData event.
Note
The CustomUnboundFieldData event is not supported in server and OLAP mode.
To learn more about unbound data, see Unbound Fields.

Example
This example demonstrates how to add an unbound field to the PivotGridControl, to show the total sum of an order.
The PivotGridControl is bound to the Order Details data table (from the nwind sample database), which contains UnitPrice, Quantity and Discount fields. The total sum is calculated as follows: UnitPriceQuantity(1-Discount).
To solve this task, create a PivotGrid's field and set its PivotGridField.UnboundType property to FieldUnboundColumnType.Decimal. Then, handle the CustomUnboundFieldData event and populate the field with data.
MainWindow.xaml |
<Window xmlns:dxpg="http://schemas.devexpress.com/winfx/2008/xaml/pivotgrid"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="600" Width="800"
x:Class="UnboundFieldExample.MainWindow"
Loaded="Window_Loaded">
<Grid>
<dxpg:PivotGridControl CustomUnboundFieldData="pivotGridControl1_CustomUnboundFieldData"
CustomCellValue="PivotGridControl1_CustomCellValue"
Name="pivotGridControl1">
<dxpg:PivotGridControl.Fields>
<dxpg:PivotGridField Name="fieldOrderID" FieldName="OrderID" Area="RowArea"/>
<dxpg:PivotGridField Name="fieldProductName" FieldName="ProductName" Area="RowArea"/>
<dxpg:PivotGridField Name="fieldUnitPrice" FieldName="UnitPrice" Area="DataArea"/>
<dxpg:PivotGridField Name="fieldQuantity" FieldName="Quantity" Area="DataArea"/>
<dxpg:PivotGridField Name="fieldDiscount" FieldName="Discount" Area="DataArea"
CellFormat="p"/>
<dxpg:PivotGridField Name="fieldTotalSum" UnboundType="Decimal" Area="DataArea"
Caption="Total Sum"/>
</dxpg:PivotGridControl.Fields>
</dxpg:PivotGridControl>
</Grid>
</Window>
|
MainWindow.xaml.vb |
Imports System.Windows
Imports DevExpress.Xpf.PivotGrid
Imports System
Namespace UnboundFieldExample
Partial Public Class MainWindow
Inherits Window
Private dataTable As New DataSet1.OrderDetailsDataTable()
Private dataAdapter As New DataSet1TableAdapters.OrderDetailsTableAdapter()
Public Sub New()
InitializeComponent()
pivotGridControl1.DataSource = dataTable
End Sub
Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
dataAdapter.Fill(dataTable)
End Sub
Private Sub pivotGridControl1_CustomUnboundFieldData(ByVal sender As Object, ByVal e As PivotCustomFieldDataEventArgs)
If e.Field Is fieldTotalSum Then
Dim unitPrice As Decimal = Convert.ToDecimal(e.GetListSourceColumnValue("UnitPrice"))
Dim qty As Integer = Convert.ToInt32(e.GetListSourceColumnValue("Quantity"))
Dim discount As Decimal = Convert.ToDecimal(e.GetListSourceColumnValue("Discount"))
e.Value = unitPrice * qty * (1 - discount)
End If
End Sub
Private Sub PivotGridControl1_CustomCellValue(ByVal sender As Object, ByVal e As PivotCellValueEventArgs)
If e.DataField Is fieldDiscount AndAlso e.RowValueType = FieldValueType.GrandTotal Then
e.Value = String.Empty
End If
End Sub
End Class
End Namespace
|
MainWindow.xaml.cs |
using System.Windows;
using DevExpress.Xpf.PivotGrid;
using System;
namespace UnboundFieldExample
{
public partial class MainWindow : Window {
DataSet1.OrderDetailsDataTable dataTable = new DataSet1.OrderDetailsDataTable();
DataSet1TableAdapters.OrderDetailsTableAdapter dataAdapter = new DataSet1TableAdapters.OrderDetailsTableAdapter();
public MainWindow() {
InitializeComponent();
pivotGridControl1.DataSource = dataTable;
}
private void Window_Loaded(object sender, RoutedEventArgs e) {
dataAdapter.Fill(dataTable);
}
private void pivotGridControl1_CustomUnboundFieldData(object sender,
PivotCustomFieldDataEventArgs e) {
if(e.Field == fieldTotalSum) {
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);
}
}
private void PivotGridControl1_CustomCellValue(object sender, PivotCellValueEventArgs e)
{
if (e.DataField == fieldDiscount && e.RowValueType == FieldValueType.GrandTotal)
e.Value = String.Empty;
}
}
}
|