XtraReport Class

A base class for a report.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v20.2.dll

Declaration

public class XtraReport :
    XtraReportBase,
    ISupportInitialize,
    IServiceProvider,
    IServiceContainer,
    IReport,
    IDocumentSource,
    ILink,
    IComponent,
    IDisposable,
    IExtensionsProvider,
    IParameterSupplier,
    IParameterSupplierBase,
    IRootXmlObject,
    IReportEvents

Remarks

Follow the steps below to create a report in code:

  • Create a report - the XtraReport class’s instance.
  • Assign a data source to the report’s DataSource property.
  • 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.
  • Create styles for report elements.

See Cross-Platform Reporting for information on how to preview, print and/or export reports in an application on different platforms.

Use the Report Designer to create reports at design time (see Get Started with DevExpress Reporting to start and Detailed Guide to DevExpress Reporting to get more information). You can also create a reporting application to allow end users to create reports in the End-User Report Designer.

Examples

The code sample below creates a new report, sets its name, display name, paper kind and margins, and adds the Detail Band band with the XRLabel control on it.

result-static-report-runtime

using System.Drawing;
using System.Drawing.Printing;
using DevExpress.XtraReports.UI;
// ...
public static XtraReport CreateReport() {
    XtraReport report = new XtraReport() {
        Name = "SimpleStaticReport",
        DisplayName = "Simple Static Report",
        PaperKind = PaperKind.Letter,
        Margins = new Margins(100, 100, 100, 100)
    };

    DetailBand detailBand = new DetailBand() {
        HeightF = 25
    };
    report.Bands.Add(detailBand);

    XRLabel helloWordLabel = new XRLabel() {
        Text = "Hello, World!",
        Font = new Font("Tahoma", 20f, FontStyle.Bold),
        BoundsF = new RectangleF(0, 0, 250, 50),
    };
    detailBand.Controls.Add(helloWordLabel);

    return report;

The code sample below creates a simple data-bound report.

result-static-report-runtime

using System.Collections.Generic;
using System.Drawing;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
// ...
    public class ReportCreator {
        class Employee {
            public string Name { get; set; }
        }
        public static XtraReport CreateReport() {
            XtraReport report = new XtraReport() {
                DataSource = CreateDataSource(),
                StyleSheet = {
                    new XRControlStyle() { Name = "Title", Font = new Font("Tahoma", 20f, FontStyle.Bold) },
                    new XRControlStyle() { Name = "Normal", Font = new Font("Tahoma", 10f), Padding = new PaddingInfo(2, 2, 0, 0) },
                }
            };
            var reportHeaderBand = CreateReportHeader("List of employees");
            var detailBand = CreateDetail("[Name]");
            report.Bands.AddRange(new Band[] { reportHeaderBand, detailBand });
            return report;
        }
        static List<Employee> CreateDataSource() {
            return new List<Employee>() {
                new Employee() { Name = "Nancy Davolio" },
                new Employee() { Name = "Andrew Fuller" },
                new Employee() { Name = "Janet Leverling" },
                new Employee() { Name = "Margaret Peacock" },
                new Employee() { Name = "Steven Buchanan" },
                new Employee() { Name = "Michael Suyama" },
                new Employee() { Name = "Robert King" },
                new Employee() { Name = "Laura Callahan" },
                new Employee() { Name = "Anne Dodsworth" }
            };
        }
        static ReportHeaderBand CreateReportHeader(string title) {
            ReportHeaderBand reportHeaderBand = new ReportHeaderBand() {
                HeightF = 50
            };
            XRLabel titleLabel = new XRLabel() {
                Text = title,
                BoundsF = new RectangleF(0, 0, 300, 30),
                StyleName = "Title"
            };
            reportHeaderBand.Controls.Add(titleLabel);
            return reportHeaderBand;
        }
        static DetailBand CreateDetail(string expression) {
            DetailBand detailBand = new DetailBand() {
                HeightF = 25
            };
            XRLabel detailLabel = new XRLabel() {
                ExpressionBindings = { new ExpressionBinding("Text", expression) },
                BoundsF = new RectangleF(0, 0, 300, 20),
                StyleName = "Normal"
            };
            detailBand.Controls.Add(detailLabel);
            return detailBand;
        }

Implements

Show 19 items
DevExpress.Data.IEffectiveDataContainer
DevExpress.Data.Browsing.IDataContextContainer
DevExpress.Data.IFilterStringContainer
DevExpress.XtraPrinting.IBrickOwnerRepository
DevExpress.Data.IParameterSupplierBase
See Also