Skip to main content

XtraReport.CalculatedFields Property

Provides access to a report’s collection of calculated fields.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v25.1.dll

NuGet Package: DevExpress.Reporting.Core

Declaration

[SRCategory(ReportStringId.CatData)]
public CalculatedFieldCollection CalculatedFields { get; }

Property Value

Type Description
CalculatedFieldCollection

A CalculatedFieldCollection object.

Remarks

For general information, see Calculated Fields Overview.

For a step-by-step tutorial, see Using Calculated Fields.

Example

This example demonstrates how to create a calculated field at runtime, and bind the field to the report control’s Text property.

using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.Configuration;
// ...
// Create a report.
XtraReport1 report = new XtraReport1();

// Create a calculated field 
// and add it to the report's collection.
CalculatedField calcField = new CalculatedField();
report.CalculatedFields.Add(calcField);

// Specify the calculated field's properties.
calcField.DataSource = report.DataSource;
calcField.DataMember = report.DataMember;
calcField.FieldType = FieldType.Double;
calcField.DisplayName = "Calculated Field";
calcField.Name = "myField";
calcField.Expression = "[UnitPrice] * [UnitsInStock]";

// Bind the label's Text property to the calculated field.
report.FindControl("xrlabel3", true).ExpressionBindings
            .Add(new ExpressionBinding() {
                EventName = "BeforePrint",
                PropertyName = "Text",
                Expression = "FormatString('{0:c2}', [myField])"
            });
See Also