A newer version of this page is available. Switch to the current version.

XtraReport Class

A base class for a report.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v18.2.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

Related API Members

The following members accept/return XtraReport objects:

Show 49 links
Library Related API Members
WPF Controls GridReportManagerService.GenerateReport(XtraReport)
IReportManagerService.GenerateReport(XtraReport)
IReportManagerService.GetReport(ReportInfo)
IReportProvider.GetReport()
IReportProvider.GetReport(String)
IReportSerializer.Load(Stream)
IReportStorage.CreateNew()
IReportStorage.CreateNewSubreport()
IReportStorage.Load(String, IReportSerializer)
IWizardReportProvider.NewReport
IWizardReportProvider.OriginalReport
ReportClonedEventArgs.Cloned
ReportClonedEventArgs.Original
ReportDesignerDocument.Report
ReportManagerService.GenerateReport(XtraReport)
ReportManagerService.GetReport(ReportInfo)
StandaloneReportManagerService.GenerateReport(XtraReport)
ASP.NET Controls and MVC Extensions DocumentViewerSettings.Report
ReportViewerSettings.Report
Reporting ASPxDocumentViewer.Report
CachedReportSourceWeb.Report
CustomizeParameterEditorsEventArgs.Report
DrillThroughContext.Report
GetValueEventArgs.Report
IReportResolver.Resolve(String, Boolean)
IWebDocumentViewerDrillThroughProcessor.CreateReport(DrillThroughContext)
IWebDocumentViewerReportResolver.Resolve(String)
ReportDesignTool.Report
ReportGenerator.GenerateReport(BaseView)
ReportGenerator.GenerateReport(BaseView, ReportGenerationOptions)
ReportGenerator.GenerateReport(BaseView, ReportGenerationOptions, Boolean)
ReportGenerator.GenerateReport(XtraReport, BaseView)
ReportGenerator.GenerateReport(XtraReport, BaseView, ReportGenerationOptions, Boolean)
ReportViewer.Report
SubreportBase.ReportSource
TypeNameBasedReportResolver.Resolve(String)
XRControl.RootReport
XRCrossBandControl.RootReport
XRDesignPanel.Report
XtraReport.FromFile(String, Boolean)
XtraReport.FromStream(Stream, Boolean)
XtraReport.MasterReport
Dashboard CustomExportEventArgs.Report
CustomExportWebEventArgs.Report
eXpressApp Framework CreateCustomReportDesignRepositoryItemEventArgs.Report
IReportContainer.Report
ReportContainer.Report
ReportsStorage.LoadReport(IReportDataV2)
ReportWebViewerDetailItem.Report

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.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