|
Report Application Server .NET SDK Developer Guide
|
|
To add and remove formula fields
|
|
These samples show how to add and remove a formula field to a Crystal report. Formula fields allow you to put data on the report that may not exist in any of the data fields.
For example, to calculate the number days it takes to process each order, you need a formula that determines the number of days between the order date and the ship date. These formulas are added to the FormulaFields collection, which can be modified by using the DataDefController class.
To add or remove a formula field:
- Call the DataDefController property of ReportClientDocument class to retrieve an instance of the DataDefController class.
- Call the FormulaFieldController property of DataDefController class to retrieve an instance of the FormulaFieldController class.
- Add a formula field to the report by with the Add method and remove a formula field from the report with the Remove method. The Add method returns the index of the item after it has been added to the FormulaFields collection.
Adding a formula field
This sample adds a formula field to the detail area of a report.
|
Visual Basic
|
|
|
Private Sub AddFormulaField(ByVal rcd As ISCDReportClientDocument, ByVal formulaField As FormulaField) Dim dataDefController As DataDefController = rcd.DataDefController Dim formulaFieldController As FormulaFieldController = dataDefController.FormulaFieldController Dim returnedIndex As Integer = formulaFieldController.Add(formulaField) Dim fieldObject As FieldObject = New FieldObjectClass() fieldObject.FieldValueType = formulaField.Type fieldObject.DataSourceName = formulaField.FormulaForm fieldObject.Left = 9400 Dim reportDef As ReportDefController2 = rcd.ReportDefController Dim sectionToAddTo As Section = rcd.ReportDefinition.DetailArea.Sections(0) reportDef.ReportObjectController.Add(fieldObject, sectionToAddTo, 0) End Sub
|
|
C#
|
|
|
private void AddFormulaField(ISCDReportClientDocument rcd, FormulaField formulaField) { DataDefController dataDefController = rcd.DataDefController; FormulaFieldController formulaFieldController = dataDefController.FormulaFieldController; int returnedIndex = formulaFieldController.Add(formulaField); FieldObject fieldObject = new FieldObjectClass(); fieldObject.FieldValueType = formulaField.Type; fieldObject.DataSourceName = formulaField.FormulaForm; fieldObject.Left = 9400; ReportDefController2 reportDef = rcd.ReportDefController; Section sectionToAddTo = rcd.ReportDefinition.DetailArea.Sections[0]; reportDef.ReportObjectController.Add(fieldObject, sectionToAddTo, 0); }
|
This list includes the namespaces used by the sample code:
- CrystalDecisions.Enterprise
- CrystalDecisions.ReportAppServer.ClientDoc
- CrystalDecisions.ReportAppServer.DataDefModel
- CrystalDecisions.ReportAppServer.Controllers
- CrystalDecisions.ReportAppServer.ReportDefModel
Removing a formula field
|
Visual Basic
|
|
|
Private Sub RemoveFormulaField(ByVal rcd As ISCDReportClientDocument, ByVal formulaField As FormulaField) Dim dataDefController As DataDefController = rcd.DataDefController Dim formulaFieldController As FormulaFieldController = dataDefController.FormulaFieldController formulaFieldController.Remove(formulaField) End Sub
|
|
C#
|
|
|
private void RemoveFormulaField(ReportClientDocument rcd) { DataDefController dataDefController = rcd.DataDefController; FormulaFieldController formulaFieldController = dataDefController.FormulaFieldController; formulaFieldController.Remove(formulaField); }
|
This list includes the namespaces used by the sample code:
- CrystalDecisions.Enterprise
- CrystalDecisions.ReportAppServer.ClientDoc
- CrystalDecisions.ReportAppServer.DataDefModel
- CrystalDecisions.ReportAppServer.Controllers
© 2021 SAP AG. All rights reserved.
http://www.sap.com/sapbusinessobjects/
Support services
http://service.sap.com/bosap-support/
Created with the Personal Edition of HelpNDoc: Create help files for the Qt Help Framework