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

XtraReport Class

A base class for a report.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v19.1.dll

Declaration

public class XtraReport :
    XtraReportBase,
    ISupportInitialize,
    IServiceProvider,
    IServiceContainer,
    IReport,
    IDocumentSource,
    ILink,
    IComponent,
    IDisposable,
    IExtensionsProvider,
    IParameterSupplier,
    IParameterSupplierBase,
    IRootXmlObject
Public Class XtraReport
    Inherits XtraReportBase
    Implements ISupportInitialize,
               IServiceProvider,
               IServiceContainer,
               IReport,
               IDocumentSource,
               ILink,
               IComponent,
               IDisposable,
               IExtensionsProvider,
               IParameterSupplier,
               IParameterSupplierBase,
               IRootXmlObject

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 Report Designer (see Create End-User Reporting Applications).

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 DevExpress.XtraReports.UI;

// ...

public static XtraReport CreateReport() {

    // Create an XtraReport instance
    XtraReport report = new XtraReport() {
        Name = "SimpleStaticReport",
        DisplayName = "Simple Static Report",
        PaperKind = PaperKind.Letter,
        Margins = new Margins(100, 100, 100, 100)
    };

    // Create a Detail band for the report
    DetailBand detailBand = new DetailBand() {
        HeightF = 25
    };

    // Add the created Detail band to the report
    report.Bands.Add(detailBand);

    // Create an XRLabel control for the report
    XRLabel helloWordLabel = new XRLabel() {
        Text = "Hello, World!",
        Font = new Font("Tahoma", 20f, FontStyle.Bold),
        BoundsF = new RectangleF(0, 0, 250, 50),
    };

    // Add the created XRLabel to the Detail band
    detailBand.Controls.Add(helloWordLabel);

    // Return the report with a band and a label on it
    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;

// ...

class Employee {
    public string Name { get; set; }
}

// Create a report and assign bands to it.
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;
}

// Create an employees list to serve as the report's data source.
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" }
    };
}

// Create a Report Header band and add a report title label to it.
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;
}

// Create a Detail band and add an employee name label to it.
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

DevExpress.XtraPrinting.IBrickOwner
DevExpress.Utils.Serializing.Helpers.IXtraSupportDeserializeCollectionItem
DevExpress.Utils.Serializing.IXtraSerializable
DevExpress.Data.IDataContainerBase
DevExpress.Data.IDataContainerBase2
DevExpress.Data.Browsing.IDataContextContainer
DevExpress.Data.IFilterStringContainer
DevExpress.XtraPrinting.IBrickOwnerRepository
DevExpress.Data.IParameterSupplierBase
See Also