The requested page is not available for the requested platform. You are viewing the content for Default platform.

Create a Simple Static Report (Runtime Sample)

This tutorial illustrates how to create a simple report that is not connected to an external data source, and contains a single label that displays static text.

For a code sample demonstrating the creation of a data-aware report, see Create a Master-Detail Report (Runtime Sample).

Perform the actions below to create and publish a report at runtime.

Create a Reporting Application

To get started with this tutorial, open a reporting application or create a new one from scratch. To learn how to create a reporting application on the platform of your choice, see Adding a Report to Your .NET Application.

Most reports you create are platform-agnostic, which means that you can use them later in applications created under any of the supported platforms. To learn more, see CodeDOM Serialization.

Create a Report in Code

The following code illustrates how to create a simple "Hello, World!" report at runtime by creating a new class inherited from the XtraReport class.

Before running this code, add all required assemblies to the References list of your project. The required assemblies may be different, depending on your application's target platform. To learn more, see Application Deployment.

The report in this sample contains an XRLabel (named HelloWorldLabel), which is placed onto a Detail band. The PageHeader and PageFooter bands do not contain any controls and are added to the report only for illustration.

using System.Drawing;
using DevExpress.XtraReports.UI;

namespace MyReportsNamespace {

    public class MyReport : XtraReport {

        private DetailBand Detail;
        private PageHeaderBand PageHeader;
        private PageFooterBand PageFooter;
        private XRLabel HelloWorldLabel;

        public MyReport() {
            this.Detail = new DetailBand();
            this.PageHeader = new PageHeaderBand();
            this.PageFooter = new PageFooterBand();
            this.PageFooter.Height = 30;
            this.PageHeader.Height = 30;

            this.Bands.AddRange(new Band[] { this.Detail, this.PageHeader, this.PageFooter });

            this.HelloWorldLabel = new XRLabel();
            this.HelloWorldLabel.Text = "Hello, World!";
            this.HelloWorldLabel.Font = new Font("Tahoma", 15, FontStyle.Bold);

            this.Detail.Controls.Add(this.HelloWorldLabel);
        }
    }
}

Preview and Publish the Report

The following image shows the results.

result-static-report-runtime

To learn how to preview, print and/or export reports in an application depending on its target platform, see Cross-Platform Reporting.

See Also