CalculatedFieldCollection Class
A collection of CalculatedField objects.
Namespace: DevExpress.XtraReports.UI
Assembly: DevExpress.XtraReports.v21.2.dll
NuGet Package: DevExpress.Reporting.Core
Declaration
public class CalculatedFieldCollection :
Collection<CalculatedField>,
IEnumerable<ICalculatedField>,
IEnumerable,
IDisposable
Remarks
This collection is returned via the XtraReport.CalculatedFields property. For more information on using calculated data fields in XtraReports, refer to the Calculated Fields Overview document.
Example
This example demonstrates how a calculated field can be created at runtime and bound to a control’s XRControl.Text property.
using System;
using System.Windows.Forms;
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.Configuration;
// ...
private void button1_Click(object sender, EventArgs e) {
// 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);
// Define 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 a label's Text property to the calculated field.
report.FindControl("xrlabel1", true).ExpressionBindings.Add(new ExpressionBinding("BeforePrint", "Text", "FormatString('{0:c2}', [myField])"));
// Display the report.
ReportPrintTool printTool = new ReportPrintTool(report);
printTool.ShowPreviewDialog();
}
Implements
Inheritance
See Also