Skip to main content

XRPivotGrid.CustomUnboundFieldData Event

Enables data to be provided for unbound fields.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v24.2.dll

NuGet Package: DevExpress.Reporting.Core

Declaration

public event EventHandler<CustomFieldDataEventArgs> CustomUnboundFieldData

Event Data

The CustomUnboundFieldData event's data class is DevExpress.XtraReports.UI.PivotGrid.CustomFieldDataEventArgs.

Remarks

The CustomUnboundFieldData event is fired for unbound fields only. To create an unbound field, add an XRPivotGridField object to the XRPivotGrid.Fields collection, and set its PivotGridFieldBase.UnboundType property to an appropriate value according to the type of data the field is supposed to display. This field name of the XRPivotGridField object must be unique, and not refer to any field in the control’s underlying data source.

The XRPivotGrid control fires the CustomUnboundFieldData event for each row and for each unbound field in the data source. The currently processed row is identified by the CustomFieldDataEventArgsBase`1.ListSourceRowIndex property which specifies the row’s index in the data source. The current unbound field is identified by the CustomFieldDataEventArgsBase`1.Field property. To provide data for a cell, assign a value to the CustomFieldDataEventArgsBase`1.Value property.

You may want to retrieve values from specific fields and rows in the data source. To do this use the CustomFieldDataEventArgsBase`1.GetListSourceColumnValue method.

Example

The code snippet below demonstrates how to create an unbound field in code and supply it with data using the PivotGridControl.CustomUnboundFieldData event. In this example, extended price values are calculated manually as follows: UnitPrice * Quantity * (1-Discount)

PivotGridContol.CustomUnboundFieldData_ex

using DevExpress.XtraPivotGrid;

// ...
        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);
            }
        }
    }
}
See Also