windowsforms-114962-controls-and-libraries-data-grid-export-and-printing-advanced-grid-printing-and-exporting.md
The WinForms Report Generator components allows you to convert the DevExpress WinForms Grid control to a report. You can generate reports for the following view types:
Follow the steps below to generate a report at design time:
Drop the ReportGenerator component from the Toolbox onto a Form.
Open the ReportGenerator’s smart tag menu and click “Generate Report”:
Select the source View and click Next :
Specify whether to display column headers and a footer with total summaries. Click Next to proceed:
Specify whether to display group rows and footers with group summaries:
Configure the following appearance settings:
Specify a name for the report, then click Finish.
Using the ReportGenerator.GenerateReport static method to generate a report:
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.ReportGeneration;
using DevExpress.Utils;
using System;
namespace DXApplication {
public partial class Form1 : DevExpress.XtraBars.Ribbon.RibbonForm {
XtraReport dataGridReport;
public Form1() {
InitializeComponent();
gridControl1.ForceInitialize();
dataGridReport = ReportGenerator.GenerateReport(gridView1,
new ReportGenerationOptions() {
EnablePrintAppearanceEvenRow = DefaultBoolean.True,
EnablePrintAppearanceOddRow = DefaultBoolean.True,
PrintColumnHeaders = DefaultBoolean.True,
PrintVerticalLines = DefaultBoolean.True,
PrintHorizontalLines = DefaultBoolean.False
});
}
//...
}
}
Imports DevExpress.XtraReports.UI
Imports DevExpress.XtraReports.ReportGeneration
Imports DevExpress.Utils
Imports System
Namespace DXApplication
Partial Public Class Form1
Inherits DevExpress.XtraBars.Ribbon.RibbonForm
Private dataGridReport As XtraReport
Public Sub New()
InitializeComponent()
gridControl1.ForceInitialize()
dataGridReport = ReportGenerator.GenerateReport(gridView1, New ReportGenerationOptions() With {
.EnablePrintAppearanceEvenRow = DefaultBoolean.True,
.EnablePrintAppearanceOddRow = DefaultBoolean.True,
.PrintColumnHeaders = DefaultBoolean.True,
.PrintVerticalLines = DefaultBoolean.True,
.PrintHorizontalLines = DefaultBoolean.False
})
End Sub
'...
End Class
End Namespace
To take advantage of binding expressions, use the ReportGenerator.GenerateReport method with the useExpressionBindings Boolean parameter set to true. Binding expressions offer advanced capabilities for further customization of the generated report. See Data Binding Modes to learn more.
//...
XtraReport report = ReportGenerator.GenerateReport(gridView1, options, true);
' ...
Dim report As XtraReport = ReportGenerator.GenerateReport(gridView1, options, True)
The following code displays the MyReport when a user clicks the “Preview” toolbar command. MyReport was generated and configured at design-time.
using DevExpress.XtraReports.UI;
using System;
//...
public partial class Form1 : DevExpress.XtraBars.Ribbon.RibbonForm {
MyReport gridReport;
public Form1() {
InitializeComponent();
gridReport = new MyReport();
}
void previewBarItem_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) {
gridReport.ShowPreviewDialog();
}
void reportDesignerBarItem_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) {
gridReport.ShowDesignerDialog();
}
void printBarItem_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) {
gridReport.PrintDialog();
}
}
Imports DevExpress.XtraReports.UI
Imports System
'...
Partial Public Class Form1
Inherits DevExpress.XtraBars.Ribbon.RibbonForm
Private gridReport As MyReport
Public Sub New()
InitializeComponent()
gridReport = New MyReport()
End Sub
Private Sub previewBarItem_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs)
gridReport.ShowPreviewDialog()
End Sub
Private Sub reportDesignerBarItem_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs)
gridReport.ShowDesignerDialog()
End Sub
Private Sub printBarItem_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs)
gridReport.PrintDialog()
End Sub
End Class
The following image shows the result:
The generated report is automatically added to the current project under the specified name and opened in the advanced Report Designer, which is fully integrated into the Visual Studio IDE. The report’s declaration can be found in the file with the same name as the report name.
The report designer provides rich creating, editing and publishing capabilities including the following.
See the Visual Studio Report Designer document for more information about report design-time customization.
After the report is generated and customized, you can show the report’s print preview to your end-users.
It is possible to delegate report customization to end-users. They can use the End-User Report Designer to manually modify the report, show a Print Preview, export the report, etc. For more information, refer to the Report Designer document.
The following code creates a new instance of the generated report class and opens it in the End-User Report Designer.
using DevExpress.XtraReports.UI;
//...
MyReport report = new MyReport();
ReportDesignTool designTool = new ReportDesignTool(report);
designTool.ShowDesignerDialog();
Imports DevExpress.XtraReports.UI
'...
Dim report As New MyReport()
Dim designTool As New ReportDesignTool(report)
designTool.ShowDesignerDialog()
The report generation engine does not support the following features: