C1Report Tips
The following tips relate to the C1Report component.
Tip 1: Converting Microsoft Access Reports
One of the most powerful features of the C1ReportDesigner application is the ability to import reports created with Microsoft Access. To import reports from an Access file, click the Application button and select Import from the menu. In the dialog box, select a Microsoft Access file (MDB or ADP) and reports.
Note that you must have Access installed on the computer to convert an Access report. Once the report is imported into the Designer, Access is no longer required. For details and more information, see Importing Microsoft Access Reports.
Tip 2: Styling Your Reports
You can use the Style Gallery in the C1ReportDesigner application to style your report using one of over 30 built-in styles. You can also create your own custom report styles. Built-in styles include standard Microsoft AutoFormat themes, including Vista and Office 2007 themes. You can access the Style Gallery from the C1ReportDesigner application by selecting the Arrange tab and clicking Styles. For details see Style Gallery.
Tip 3: Using Script Expressions
Expressions are widely used throughout a report definition to retrieve, calculate, display, group, sort, filter, parameterize, and format the contents of a report. Some expressions are created for you automatically (for example, when you drag a field from the Toolbox onto a section of your report, an expression that retrieves the value of that field is displayed in the text box). However, in most cases, you create your own expressions to provide more functionality to your report.
For more information about taking advantage of script expressions, see Creating VBScript Expressions, Working with VBScript, and Expressions, Scripts, Tags.
Tip 4: Creating Subreports
A subreport is a report that is inserted in another report. Subreports are useful when you want to combine several reports into one. For example, you may have a main report that integrates several subreports into a single main report. Or you can use the main report to show detailed information and use subreports to show summary data at the beginning of each group. For information about subreports, see the Subreport property in the reference section, and for an example see Creating a Master-Detail Report Using Subreports.
Tip 5: Understanding Reports and Report Definitions
Reports are based on a report definition, an XML file that describes data and layout. Reports for WinForms creates the report definition for you when you add a report item to a project and define the report layout. When report execution is triggered (for example, you provide a button that the user clicks to view a report), the C1Report control retrieves data using the data bindings you have defined and merges the result set into the report layout. The report is presented in the native output format for the control you are using.
You can load report definitions at design time or run time, from XML files, strings, or you can create and customize report definitions dynamically using code.
Tip 6: CustomFields and Chart/Reports Version
You can include a chart in a report by adding the C1Chart object to C1Report's custom field. This method is demonstrated in detail in the CustomFields sample installed with Reports for WinForms. Along with the sample, a pre-built CustomFields assembly – just as can be built with that sample – is shipped, together with several other DLLs (such as the C1Chart assembly) as part of the C1ReportDesigner application installed by default in the C1Report/Designer folder in the Studio for WinForms installation directory.
You may be tempted to just add a reference to that prebuilt C1.C1Report.CustomFields.2.dll (or C1.C1Report.CustomFields.4.dll) file to your own project when including a chart in a report in a C1Report-based application. While this may work initially, it may cause unexpected problems later. The binary CustomFields assembly shipped with the C1ReportDesigner application is built with references to specific versions of C1Report and C1Chart located in the C1ReportDesigner application's subfolder. When you install Studio for WinForms you will have the same versions of the reports and chart products as the components you may use in your own application development. But if you later update just one assembly, for example just C1Chart, the prebuilt CustomFields in your application will suddenly no longer work since it will be referencing an outdated C1Chart assembly after upgrading the chart.
For that reason it is much better and a best practice to add the actual CustomFields project (together with the source code) from the corresponding sample (available in both VB.NET and C# variants) to your own solution, and reference that project instead of the prebuilt binary CustomFields assembly. Then upgrading any of the involved ComponentOne products will not break your application.
Tip 7: Adding a Custom Outline Entry for Each Data Record
Outline entries are automatically generated for group headers in C1Report; the AddOutlineEntry event allows customizing the text of those entries. To associate a customized outline entry with each record of a report that otherwise is not using groups, follow the following steps:
1. Create a group that will always contain exactly one record. The easiest way to do that is to group records by a key field.
2. On that group, create a group header with the minimal height of 1 twip so that it won't show in the report. The AddOutlineEntry event will be fired for each instance of that group.
3. Attach a handler to the AddOutlineEntry event to customize the entry's text by modifying the Text property on the ReportEventArgs passed to the handler.
This will associate a customized outline entry with each record of a report that otherwise is not using groups.
Tip 8: Printing Two Subreports Side by Side
While it is possible to create a report definition with two subreports arranged side by side on a page, generally speaking the C1Report component cannot properly render such subreports if they take up more than one page and page breaks are involved. Sometimes though, it is possible to render such reports correctly by importing the report definition into a C1PrintDocument component and rendering that instead. For example:
Dim doc As New C1PrintDocument()
doc.ImportC1Report("myReportFile.xml", "myReportName")
doc.Generate()
• C#
C1PrintDocument doc = new C1PrintDocument();
doc.ImportC1Report("myReportFile.xml", "myReportName");
doc.Generate();
See Generating Reports (C1Report vs. C1PrintDocument) and Deciding on Report Generation Method for details concerning advantages and limitations of importing reports into a C1PrintDocument instead of using C1Report directly.
Tip 9: Passing Parameters from the Main Report into a Subreport
To pass parameters from the main report to a subreport set the ExposeScriptObjects property to True in the main report. When you do so, all fields of the main report will become visible in the subreport.
So, for instance, if you took the CommonTasks.xml report shipped with the Reports for WinForms samples, and in report "14: Page Headers in Subreports", set ExposeScriptObjects to True, you can use the CategoryName (defined in the main report but not in the subreport) in the subreport's fields.
Tip 10: Linking a Subreport to a Report Using Multiple Fields
Normally when a subreport is used to print part of a report the linkage between the report and the subreport is maintained via the Text property of the field containing the subreport, somewhat like the following example:
"SubReportLookupField = \" & ReportKeyField & \""
At run time that expression is calculated, yielding something similar to the following:
SubReportLookupField = "1"
The result is used as a filter for the subreport's data source (RowFilter property).
The interesting thing here is that the initial expression may be more complex and may references to several fields. For instance, suppose the main report has DateTime type fields StartTime and EndTime, while the subreport has an OpenTime field, also of the DateTime type. Suppose the subreport must show only those records for which the following condition is true:
OpenTime >= StartTime and OpenTime <= EndTime
In that case the following string may be used as the subreport filter (all on a single line):
"OpenTime >= #" & Format(StartTime, \"MM/dd/yyyy\") & "# and OpenTime <= #" & Format(EndTime, \"MM/dd/yyyy\") & "#"
The Format function is used here to format DateTime values using InvariantCulture, as that is the format that should be used for the RowFilter.
|