Back to Devexpress

CalculatedFieldCollection Class

xtrareports-devexpress-dot-xtrareports-dot-ui-1aafa686.md

latest4.2 KB
Original Source

CalculatedFieldCollection Class

A collection of CalculatedField objects.

Namespace : DevExpress.XtraReports.UI

Assembly : DevExpress.XtraReports.v25.2.dll

NuGet Package : DevExpress.Reporting.Core

Declaration

csharp
public class CalculatedFieldCollection :
    Collection<CalculatedField>,
    IEnumerable<ICalculatedField>,
    IEnumerable,
    IDisposable
vb
Public Class CalculatedFieldCollection
    Inherits Collection(Of CalculatedField)
    Implements IEnumerable(Of ICalculatedField),
               IEnumerable,
               IDisposable

The following members return CalculatedFieldCollection objects:

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 to create a calculated field at runtime, and bind the field to the report control’s Text property.

csharp
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])"
            });
vb
Imports DevExpress.XtraReports.UI
Imports DevExpress.XtraReports.Configuration
' ...
' Create a report.
Dim report As New XtraReport1()

' Create a calculated field 
' and add it to the report's collection.
Dim calcField As 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("xrlabel3", True).ExpressionBindings.Add(New ExpressionBinding("BeforePrint", "Text", "FormatString('{0:c2}', [myField])"))

Inheritance

Object Collection<CalculatedField> CalculatedFieldCollection

See Also

CalculatedFieldCollection Members

Use Calculated Fields

DevExpress.XtraReports.UI Namespace