Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to Add an Unbound Field to Supply Additional Data

  • 2 minutes to read

The following code snippet adds two unbound fields which represent a discount and discount value for orders. For analyzing purposes, a discount of 10% is applied to all the orders in a bound data source. A discount value is calculated for each payment referenced by the DBPivotGridPaymentAmount field.

var
  I: Integer;
  ADiscountField: TcxPivotGridField;
begin
  DBPivotGrid.BeginUpdate;
  ADiscountField := DBPivotGrid.CreateField;
  with ADiscountField do
  begin
    Caption := 'Discount';
    DisplayFormat := '0.0%';
    SummaryType := stMin;
    Visible := True;
    Area := faData;
    DataBinding.ValueType := 'Float';
    for I := 0 to PivotGrid.DataController.RecordCount - 1 do
      Values[I] := 10;
  end;
  with DBPivotGrid.CreateField do
  begin
    Caption := 'Discount value';
    SummaryType := stSum;
    Visible := True;
    Area := faData;
    DataBinding.ValueType := 'Currency';
    with PivotGrid.DataController do
      for I := 0 to RecordCount - 1 do
        Values[I] := Values[I, DBPivotGridPaymentAmount.Index] *
          Values[I, ADiscountField.Index] / 100;
  end;
  DBPivotGrid.EndUpdate;
end;