Xceed Grid for WinForms v4.3 Documentation
The Report class

Welcome to Xceed Grid for WinForms v4.3 > Basic Concepts > Reporting > The Report class

The Report class represents a report generated from the data contained within an instance of a GridControl. Although the reporting capabilities of Xceed Grid for WinForms can be used with minimal programming by using the provided end-user forms (GenerateReportForm and CustomizeReportStyleForm, which is called in the former), you can forgo using these forms and perform the functions they contain programmatically. 

The following code will instantiate the Report class:

VB.NET Copy Code
Dim report As New Report( Me.gridControl1 )
C# Copy Code
Report report = new Report( this.gridControl1 );

This creates an instance of the Report class with a default report style, using the data contained within gridControl1. You can then use one of the following methods to use the report: Print, PrintPreview, Export or CreatePrintDocument. The first three methods correspond to buttons that are available in the form called GenerateReportForm. The last method allows for more control than the Print method.

Print and PrintPreview methods

These methods print and preview the report, respectively. The default printer settings are used when no argument is passed to the method:

VB.NET
Copy Code
Imports Xceed.Grid.Reporting
Dim report As New Report( Me.gridControl1 )
report.PrintPreview()
report.Print()
C#
Copy Code
using Xceed.Grid.Reporting;
Report report = new Report( this.gridControl1 );
report.PrintPreview();
report.Print();
You can also create a standard .NET PrinterSettings object and pass it to this method to specify specific print settings:
VB.NET
Copy Code
Dim report As New Report( Me.gridControl1 )
Dim printerSettings As New System.Drawing.Printing.PrinterSettings() 
'...
' Set the printer settings.
'... 
report.PrintPreview( printerSettings )
report.Print( printerSettings )
C#
Copy Code
Report report = new Report( this.gridControl1 );
System.Drawing.Printing.PrinterSettings printerSettings = new System.Drawing.Printing.PrinterSettings(); 
//...
// Set the printer settings.
//... 
report.PrintPreview( printerSettings );
report.Print( printerSettings );
The Print and PrintPreview methods in the Report class are much more powerful than the methods of the same name in the GridControl class, and give better results. The GridControl's Print and PrintPreview methods simply print or preview as if a screenshot were taken of the grid control. Elements such as GroupBy rows and the ColumnManager row are printed as they appear on-screen, and page breaks can occur anywhere. By contrast, the Print and PrintPreview methods of the Report class let you configure the appearance of the report and output the data more intelligently.

The Export method

The ExportFormat enum value passed to the Export method determines which format will be used to export the report:  

Export Format Page Format
PDF Multi-page format.
HTML Continuous format.
JPEG Single-page format.
TIFF Multi-page format.

If you export to a PDF, HTML or TIFF file, the entire report is exported in a single file. With HTML format, all of the report's information is presented in a single, continuous page. 

If however you export a report using the JPEG format, each page of the report will be exported to a separate file with a number attaced to the filename. For example, consider this code:

VB.NET
Copy Code
Imports Xceed.Grid.Reporting
Dim report As New Report( Me.gridControl1 )
report.Export( "D:\report", ExportFormat.Jpeg, True, True )
C#
Copy Code
using Xceed.Grid.Reporting;
Report report = new Report( this.gridControl1 );
report.Export( "D:\\report", ExportFormat.Jpeg, true, true );
If the report contains three pages, three separate files will be created with this code, namely, report_001.jpeg, report_002.jpeg and report_003.jpeg. The first boolean argument specifies whether the destination file should be overwritten if it exists. If false and the file exists, an exception will be thrown. The final boolean argument specifies whether a progress report dialog should be displayed. Unless you provide your own progress report dialog, it is highly recommended to use true. Otherwise, your application might seem frozen to the end-user. 

A second version of the Export method takes an additional argument of type ExportSettings (or of the derived types PdfExportSettings or ImageExportSettings). These classes let you include information such as a title, author or description in the exported file.

VB.NET
Copy Code
Dim report As New Report( Me.gridControl1 )
Dim exportSettings As New ExportSettings()
exportSettings.Title = "Monthly report"
exportSettings.Author = "John Smith"
report.Export( "D:\report.html", ExportFormat.Html, True, True, exportSettings )
C#
Copy Code
Report report = new Report( this.gridControl1 );
ExportSettings exportSettings = new ExportSettings();
exportSettings.Title = "Monthly report";
exportSettings.Author = "John Smith";
report.Export( "D:\\report.html", ExportFormat.Html, true, true, exportSettings );

The PdfExportSettings class provides two additional properties: EncryptionPassword and UseCompression. EncryptionPassword is a string representing the password that is used to encrypt the PDF report being exported. UseCompression is a boolean indicating that the PDF file should be compressed. 

The ImageExportSettings class provides a Resolution property, which holds an ImageExportResolution value specifying whether the image should be exported with standard, fine or super-fine resolution.

The CreatePrintDocument method

The CreatePrintDocument method returns a standard .NET PrintDocument. Using the CreatePrintDocument allows for more control over the print process but means more work.

ReportStyleSheet property

An important property of the Report class is ReportStyleSheet. The object it references encapsulates the styles used in a report. See the Report styles and report style sheets topic for more details.