PivotGridControl.CustomUnboundFieldData Event

Enables providing data to unbound fields.

Namespace: DevExpress.XtraPivotGrid

Assembly: DevExpress.XtraPivotGrid.v20.1.dll

Declaration

public event CustomFieldDataEventHandler CustomUnboundFieldData
Public Event CustomUnboundFieldData As CustomFieldDataEventHandler

Event Data

The CustomUnboundFieldData event's data class is CustomFieldDataEventArgs. The following properties provide information specific to this event:

Property Description
Field Gets the unbound field currently being processed.
ListSourceRowIndex Gets the current row index in the data source.
Value Gets or sets the currently processed value.

Remarks

The CustomUnboundFieldData event allows data to be provided for unbound fields. Alternatively, you can provide data for unbound fields by specifying a string expression via the PivotGridFieldBase.UnboundExpression property.

To create an unbound field, add a PivotGridField object to the PivotGridControl.Fields collection and set its PivotGridFieldBase.UnboundType property to an appropriate value, according to the type of data the field is supposed to display. The PivotGridFieldBase.FieldName property of the PivotGridField object must be unique, and cannot refer to any field in the control's underlying data source.

The PivotGrid 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<T>.ListSourceRowIndex property, which specifies the row's index in the data source. The current unbound field is identified by the CustomFieldDataEventArgsBase<T>.Field property.

To provide data for a cell, assign a value to the CustomFieldDataEventArgsBase<T>.Value property.

You may want to retrieve values from specific fields and rows in the data source. To do this, use the CustomFieldDataEventArgsBase<T>.GetListSourceColumnValue method.

NOTE

The CustomUnboundFieldData is not supported in server and OLAP modes.

To learn more about unbound fields, see Unbound Data.

Examples

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 using the formula 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