XtraReport Class
A base class for a report.
Namespace: DevExpress.XtraReports.UI
Assembly:
DevExpress.XtraReports.v19.1.dll
NuGet Packages:
DevExpress.Reporting.Core, DevExpress.WindowsDesktop.Core
Declaration
public class XtraReport :
XtraReportBase,
ISupportInitialize,
IServiceProvider,
IServiceContainer,
IReport,
IDocumentSource,
ILink,
IComponent,
IDisposable,
IExtensionsProvider,
IParameterSupplier,
IParameterSupplierBase,
IRootXmlObject,
IReportEvents
Public Class XtraReport
Inherits XtraReportBase
Implements ISupportInitialize,
IServiceProvider,
IServiceContainer,
IReport,
IDocumentSource,
ILink,
IComponent,
IDisposable,
IExtensionsProvider,
IParameterSupplier,
IParameterSupplierBase,
IRootXmlObject,
IReportEvents
The following members return XtraReport objects:
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) |
Reporting |
ASPxDocumentViewer.Report |
CachedReportSourceWeb.Report |
CustomizeParameterEditorsEventArgs.Report |
DrillThroughContext.Report |
GetValueEventArgs.Report |
IReportJsonSerializer.DeserializeFromJson(String) |
IReportResolver.Resolve(String, Boolean) |
IWebDocumentViewerDrillThroughProcessor.CreateReport(DrillThroughContext) |
IWebDocumentViewerReportResolver.Resolve(String) |
ReportDesignTool.Report |
ReportGenerator.GenerateReport(BaseView, ReportGenerationOptions, Boolean) |
ReportGenerator.GenerateReport(BaseView, ReportGenerationOptions) |
ReportGenerator.GenerateReport(BaseView) |
ReportGenerator.GenerateReport(XtraReport, BaseView, ReportGenerationOptions, Boolean) |
ReportGenerator.GenerateReport(XtraReport, BaseView) |
ReportViewer.Report |
SubreportBase.ReportSource |
TypeNameBasedReportResolver.Resolve(String) |
XRControl.RootReport |
XRCrossBandControl.RootReport |
XRDesignPanel.Report |
XtraReport.FromFile(String, Boolean) |
XtraReport.FromStream(Stream, Boolean) |
XtraReport.FromXmlFile(String, Boolean) |
XtraReport.FromXmlStream(Stream, Boolean) |
XtraReport.MasterReport |
Dashboard |
CustomExportEventArgs.Report |
CustomExportWebEventArgs.Report |
eXpressApp Framework |
CreateCustomReportDesignRepositoryItemEventArgs.Report |
IReportContainer.Report |
ReportContainer.Report |
ReportsStorage.LoadReport(IReportDataV2) |
ReportWebViewerDetailItem.Report |
ASP.NET Web Forms Controls |
DocumentViewerSettings.Report |
ReportViewerSettings.Report |
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.
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;
}
Imports DevExpress.XtraReports.UI
' ...
Public Shared Function CreateReport() As XtraReport
' Create an XtraReport instance
Dim report As New XtraReport() With {
.Name = "SimpleStaticReport",
.DisplayName = "Simple Static Report",
.PaperKind = PaperKind.Letter,
.Margins = New Margins(100, 100, 100, 100)
}
' Create a Detail band for the report
Dim detailBand As New DetailBand() With {
.HeightF = 25
}
' Add the created Detail band to the report
report.Bands.Add(detailBand)
' Create an XRLabel control for the report
Dim helloWordLabel As New XRLabel() With {
.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
End Function
The code sample below creates a simple data-bound report.
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;
}
Imports System.Collections.Generic
Imports System.Drawing
Imports DevExpress.XtraPrinting
Imports DevExpress.XtraReports.UI
' ...
Friend Class Employee
Public Property Name() As String
End Class
' Create a report and assign bands to it.
Public Shared Function CreateReport() As XtraReport
Dim report As New XtraReport() With {
.DataSource = CreateDataSource(), .StyleSheet = {
New XRControlStyle() With {.Name = "Title", .Font = New Font("Tahoma", 20F, FontStyle.Bold)},
New XRControlStyle() With {.Name = "Normal", .Font = New Font("Tahoma", 10F), .Padding = New PaddingInfo(2, 2, 0, 0)}
}
}
Dim reportHeaderBand = CreateReportHeader("List of employees")
Dim detailBand = CreateDetail("[Name]")
report.Bands.AddRange(New Band() { reportHeaderBand, detailBand })
Return report
End Function
' Create an employees list to serve as the report's data source.
Shared Function CreateDataSource() As List(Of Employee)
Return New List(Of Employee)() From {
New Employee() With {.Name = "Nancy Davolio"},
New Employee() With {.Name = "Andrew Fuller"},
New Employee() With {.Name = "Janet Leverling"},
New Employee() With {.Name = "Margaret Peacock"},
New Employee() With {.Name = "Steven Buchanan"},
New Employee() With {.Name = "Michael Suyama"},
New Employee() With {.Name = "Robert King"},
New Employee() With {.Name = "Laura Callahan"},
New Employee() With {.Name = "Anne Dodsworth"}
}
End Function
' Create a Report Header band and add a report title label to it.
Shared Function CreateReportHeader(ByVal title As String) As ReportHeaderBand
Dim reportHeaderBand As New ReportHeaderBand() With {.HeightF = 50}
Dim titleLabel As New XRLabel() With {.Text = title, .BoundsF = New RectangleF(0, 0, 300, 30), .StyleName = "Title"}
reportHeaderBand.Controls.Add(titleLabel)
Return reportHeaderBand
End Function
' Create a Detail band and add an employee name label to it.
Shared Function CreateDetail(ByVal expression As String) As DetailBand
Dim detailBand As New DetailBand() With {.HeightF = 25}
Dim detailLabel As New XRLabel() With {.ExpressionBindings = { New ExpressionBinding("Text", expression) }, .BoundsF = New RectangleF(0, 0, 300, 20), .StyleName = "Normal"}
detailBand.Controls.Add(detailLabel)
Return detailBand
End Function
The following code snippets (auto-collected from DevExpress Examples) contain references to the XtraReport class.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
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