Http://www.cnblogs.com/star250/archive/2008/12/22/1359810.html
How do I use code to dynamically set the text, fields, and other objects in a crystal report?
Vb
First, you have to declare an object variable (eg. Textobject, Fieldobject, ...), of course not the general object, but: Dim xObject as CrystalDecisions.CrystalReports.Engine.FieldObject (field) Dim XObject as CrystalDecisions.CrystalReports.Engine.TextObject (text) Dim XObject as CrystalDecisions.CrystalReports.Engine.LineObject (lines) Dim XObject as CrystalDecisions.CrystalReports.Engine.BoxObject (rectangular box) ... Second, you must assign the real object of the Crystal report to it, for example: xObject = CrReport.ReportDefinition.ReportObjects.Item ("Fieldobjectname") xObject = CrReport.ReportDefinition.ReportObjects.Item ("Textobjectname") XObject = CrReport.ReportDefinition.ReportObjects.Item ("Lineobjectname") XObject = CrReport.ReportDefinition.ReportObjects.Item ("Boxobjectname") ... You can then invoke its various properties and methods:
For Fieldobject, you can: 1. Set the number of decimal places for numeric fields: XObject.FieldFormat.NumericFormat.DecimalPlaces = 4 2. Sets the output type of the Boolean field: XObject.FieldFormat.BooleanFormat.OutputType =crystaldecisions.shared.booleanoutputtype.yesorno 3. Set other formats such as (Com Monformat,datetimeformat,dateformat,timeformat)
For Textobject, you can: 1. Change the text: Xobject.text = "hehe" 2. Change font: Xobject.applyfont (New font, 1 0.0!)) 3. Set color: Xobject.color = color.red 3. Hide display: xObject.ObjectFormat.EnableSuppress = True
For Lineobject, you can: 1. Set line style: Xobject.linestyle = CrystalDecisions.Shared.LineStyle.DotLine 2. Set Line color: Xobject.linecolor = Color.Blue 3. Set line width: xobject.linethickness = 3 4. Set other formats (such as: Location (Top,left,right,bottom), border, etc.) for Boxobject, you can: 1. Set Fill color: xobject.fillcolor = Colo R.brown 2. Set line style: Xobject.linestyle = CrystalDecisions.Shared.LineStyle.DotLine 3. Set Line color: Xobject.linecolor = Color.Blue 4. Set line width: xobject.linethickness = 3 5. Set other formats such as: Position (top,Left,right,bottom), borders, etc.)
//c# CrystalDecisions.CrystalReports.Engine.TextObject XObject; XObject = (CrystalDecisions.CrystalReports.Engine.TextObject) crystalreportsource1.reportdocument.reportdefinition.reportobjects["Text1"]; xobject.text= "conditions";
"Go" How do you use code to dynamically set up text, fields, and other objects in a crystal report?