Use Third-Party Controls
- 3 minutes to read
This document describes how to add third-party visual elements to a report. Apart from standard controls, a report can contain controls from the System.Windows.Forms namespace, printing links or custom user-defined objects.
Embed Third-Party WinForms Controls
You can add a Windows Forms control to a report at Visual Studio design time by copying and pasting this control from its Form designer. A WinControlContainer hosts this control after adding it to the report.
A report can contain any Windows Forms visual control that supports the .NET drawing engine (based on the Graphics class that provides support for GDI+). XtraReports cannot host Win32 or ActiveX components for this reason.
Use the WinControlContainer.DrawMethod property to specify the rendering mode of a Windows Forms control.
You can print standard Windows Forms controls using the following appropriate printing links:
- ListViewLink - a link to print the ListView control.
- RichTextBoxLink - a link to print the RichTextBox control.
- TreeViewLink - a link to print the TreeView control.
- DataGridLink - a link to print the DataGrid control.
Embed DevExpress WinForms Controls
You can add a DevExpress WinForms control to a report using a PrintableComponentContainer. It enables printing documents created using printing links as well as objects that implement the IPrintable interface. The following DevExpress controls implement this interface.
Do the following to embed such a control to a report:
Prepare a WinForms application containing the controls you want to print (for instance, the GridControl in this example).
- Add a new empty report to your WinForms application.
Open the Visual Studio Toolbox (by pressing CTRL+ALT+X) and expand its DX.23.1: Report Controls tab. Drag the PrintableComponentContainer control from this tab and drop it onto the report’s detail band.
- Change the added container’s modifier to public to be able to assign the required properties outside of the XtraReport class descendant scope.
Specify the PrintableComponentContainer.PrintableComponent property to associate the Windows Forms controls with the corresponding report containers. Use the methods of the ReportPrintTool class to invoke the default Print Preview form and show a report document in it.
using System.Windows.Forms; // Create a new report instance. XtraReport1 report = new XtraReport1(); // Link the required control with the PrintableComponentContainers of a report. report.printableComponentContainer1.PrintableComponent = gridControl; // Invoke a Print Preview for the created report document. ReportPrintTool preview = new ReportPrintTool(report); preview.ShowRibbonPreview();
The following image illustrates the resulting report document containing a WinForms control.
Embed DevExpress ASP.NET Controls
You can embed the following DevExpress web controls into a report using the corresponding exporter objects:
Assign an exporter object to the PrintableComponentContainer.PrintableComponent property in code to embed the corresponding control into a report.
An online example is available at How to print DevExpress ASP.NET controls via XtraReports.