Create a Report in Code
- 2 minutes to read
The following steps describe how to create a report in code:
- Create an instance of the XtraReport class or implement an XtraReport class descendant.
- Assign a data source to the report: specify the DataSource and DataMember properties.
- Create bands and add them to the report’s Bands collection (the DetailBand is mandatory).
- Create report controls and add them to the report’s bands.
- Add styles to report elements.
After the report layout is complete, you can generate the report document and display it in a Print Preview.
Examples
The following examples illustrate how to generate specific report types in code:
- Simple Static Report
- Simple Data-Bound Report
- Table Report
- Table Report with Dynamic Columns
- Master-Detail Report
- Cross-Tab Report
- Report with a Subreport
The following topics describe the report object model and events:
Troubleshooting
If a runtime-generated report does not work as expected or you want to know how to implement a particular feature in code, follow these steps:
- Use the report’s SaveLayoutToXml method to save the generated report as a REPX file.
Add a new report to your .NET Framework project, expand the report’s smart tag, and import the generated REPX file.
Specify the report’s data source and preview the changes.
- Modify the report layout.
- The
XtraReport.Designer.cs
orXtraReport.Designer.vb
file contains code that generates the report. Use this code in your application to get a similar result.
See Also