Problem:
In the crystal report, because the fields of the data source are not fixed, can I dynamically add fields at runtime, just like dynamically adding controls in winform? (Updated: 2003-11-05)
--------------------------------------
Solution:
Use "formula field"
1. Define several "formula fields" according to the maximum number of fields, formulafeild1, formulafeild2 ......, The formula is null;
2. Place the "formula field" in the "details" order;
3. dynamically assign "formula field" to "specific field" in the program ";
For example: formulafield1.text = "{customer. Customer ID }"
--------------------------------------
Refer:
1. Retrieve the datadefinition object through the datadefinition attribute of the reportdocument object.
ReportDocument Member
Public instance attributes
Datadefinition. Obtain the datadefinition object.
2. datadefinition class
Datadefinition member | crystaldecisions. crystalreports. Engine namespace
Requirements
Namespace: crystaldecisions. crystalreports. Engine
Platform: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP
Assembly: crystaldecisions. crystalreports. Engine (in crystaldecisions. crystalreports. Engine. dll)
Contains all information related to data operations (data operations are performed based on the data source in the report ).
For a list of all members of this type, see datadefinition member.
Object
Datadefinition
Remarks
You can use this class to define the method of selecting records for reports and groups, as well as to retrieve group sets and various field definition sets.
You can use the datadefinition attribute of the reportdocument object to retrieve the datadefinition object.
3. Use the formulafielddefinitions attribute of the datadefinition object to retrieve the formulafields object.
Datadefinition Member
Datadefinition class | crystaldecisions. crystalreports. Engine namespace
Public instance attributes
Formulafields formulafielddefinitions. Obtain the formulafielddefinitions set.
4. formulafielddefinitions class
Formulafielddefinitions member | crystaldecisions. crystalreports. Engine namespace
Requirements
Namespace: crystaldecisions. crystalreports. Engine
Platform: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP
Assembly: crystaldecisions. crystalreports. Engine (in crystaldecisions. crystalreports. Engine. dll)
The formulafielddefinition object that contains each formula field in the report.
For a list of all members of this type, see formulafielddefinitions members.
Object
Scrcollection
Formulafieldfielddefinitions
Remarks
You can use the formulafields attribute of the datadefinition object to retrieve the formulafielddefinitions set.
5. Obtain the formulafielddefinition object and set the formula.
For example: formulafielddefinition. Text = "{customer. Customer ID }"
Formulafielddefinition Member
Formulafielddefinition class | crystaldecisions. crystalreports. Engine namespace
Public instance attributes
Formulaname (inherited from fielddefinition) string. Obtain the unique formula name of the field definition in the Crystal Report formula syntax.
Kind (inherited from fielddefinition) fieldkind. Obtain the field type.
Name string. Obtain the name of the formula field displayed in "field resource manager.
Numberofbytes (inherited from fielddefinition) int32. Obtains the number of bytes required to store field data in the memory.
Text string. Obtain or set the text of the formula.
Usecount (inherited from fielddefinition) int32. Obtains the number of times a field is used in a report.
Valuetype (inherited from fielddefinition) fieldvaluetype. Type of the field value.
Public instance method
Check the formula. If a syntax error exists, the error string and false are returned.