How can I use code to dynamically set text, fields, and other objects in a crystal report?
// VB
First, you must declare an object variable (eg. textobject, fieldobject,...). Of course, it is not a general object,:
Dim xobject as crystaldecisions. crystalreports. Engine. fieldobject (field)
Dim xobject as crystaldecisions. crystalreports. Engine. textobject (text)
Dim xobject as crystaldecisions. crystalreports. Engine. lineobject (line)
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 ")
......
Then, you can call its various attributes and methods:
For fieldobject, you can:
1. Set the number of decimal places in the numeric field:
Xobject. fieldformat. numericformat. decimalplaces = 4
2. Set the output type of a Boolean field:
Xobject. fieldformat. booleanformat. outputtype = crystaldecisions. Shared. booleanoutputtype. yesorno
3. Set other formats such as (commonformat, datetimeformat, dateformat, timeformat)
For textobject, you can:
1. Change text:
Xobject. Text = ""
2. Change the font:
Xobject. applyfont (new font ("", 10.0 !))
3. Set the color:
Xobject. Color = color. Red
3. Hide the display:
Xobject. objectformat. enablesuppress = true
For lineobject, you can:
1. Set the line style:
Xobject. linestyle = crystaldecisions. Shared. linestyle. dotline
2. Set the line color:
Xobject. linecolor = color. Blue
3. Set the line width:
Xobject. linethickness = 3
4. Set other formats (such as position (top, left, right, bottom) and border)
For boxobject, you can:
1. Set the fill color:
Xobject. fillcolor = color. Brown
2. Set the line style:
Xobject. linestyle = crystaldecisions. Shared. linestyle. dotline
3. Set the line color:
Xobject. linecolor = color. Blue
4. Set the line width:
Xobject. linethickness = 3
5. set other formats (such as position (top, left, right, bottom) and border)
// C #
Crystaldecisions. crystalreports. Engine. textobject xobject;
Xobject = (crystaldecisions. crystalreports. Engine. textobject) crystalreportsource1.reportdocument. reportdefinition. reportobjects ["text1"];
Xobject. Text = "condition ";