How to: Print a Scheduler Using a Report Preview (Step-by-Step Guide)
- 4 minutes to read
This example illustrates how to create a printable report based on the Scheduler data, representing one of the Scheduler views.
This approach utilizes the XtraReports Suite to create a report containing controls specially designed to represent Scheduler elements. After the report is created, the Print Preview Form is invoked, which enables the end-user to print the report or export it to PDF.
This guide consists of the following sections:
- Add a Scheduler Report to the Application
- Load a Report from a Template
- Create a Report from Scratch
- Display the Report
Steps 1-3. Add a Scheduler Report to the Application
- Open the project that contains the SchedulerControl in the Microsoft Visual Studio Designer.
In the PROJECT menu, select Add DevExpress Item -> New Item… to invoke the DevExpress Template Gallery dialog. Select the Scheduler Report template.
Click Add Item to generate the code and add the file containing the XtraSchedulerReport class descendant to the project. The Report Designer for the newly created report is invoked automatically. It is illustrated in the following image.
Steps 4-6. Load a Report from a Template
Note
To create a report from scratch, skip to Step 7.
To create a report, use one of the templates from the gallery of ready-to-use report layout templates. To connect to this gallery at design time within Visual Studio, click the report’s smart tag, and in the invoked Report Tasks list, select the Load Report Template… link.
In the invoked Report Templates dialog, select the template that best meets your requirements and click Load. You can also search for a specific template name using the search box.
The selected report is immediately loaded into the Visual Studio designer.
Steps 7-15. Create a Report from Scratch
Note
If you have loaded a report from a template in steps 4-6, skip to step 16.
To proceed with report creation, open the Toolbox pane (by pressing CTRL+ALT+X). Then, select the DayViewTimeCells control in the DX.24.1: Scheduler Reporting tab and drop it onto the report’s DetailBand. Note that this tab is visible only if the XtraSchedulerReport class is opened in the Designer.
Note
The current implementation requires that report controls reside in the DetailBand only, and not in the other report bands.
- Add the HorizontalResourceHeaders control. Place it above the DayViewTimeCells control in the Detail Band.
- Add the HorizontalDateHeaders control. Place it above the HorizontalResourceHeaders control.
- Use the HorizontalResourceHeaders control’s smart tag menu to link it to the HorizontalDateHeaders control.
Use the DayViewTimeCells control’s smart tag menu to link it to the HorizontalResourceHeaders control, as shown in the image below.
Add the DayViewTimeRuler control, place it on the left side of the DayViewTimeCells control, click its smart tag and select the dayViewTimeCells1 in the DayViewTimeCells drop-down list. The time ruler is linked to the data provider (ReportDayView) and anchored to time cells.
Drag the top and bottom edges of the DayViewTimeRuler to resize it. Its top border should be aligned to the top of the HorizontalDateHeaders control, and its bottom border should be aligned to the bottom of the DayViewTimeCells control. The visible scale of the DayViewTimeRuler starts at the offset from the top edge, which is specified by the ControlCornersOptions.Top property. To specify the offset in the Visual Studio Designer, click the smart tag of the DayViewTimeRuler and set the TopCornerIndent value, as illustrated in the following image.
Add the TimeIntervalInfo control and the CalendarControl to the Detail Band. Place them above the other controls, at the top of the page. The controls bind themselves to the DayViewTimeCells control automatically. Arrange the controls on a page by resizing and moving them. The resulting report is shown below.
Use the Detail band’s smart tag menu to specify that the page break is inserted after the band, as illustrated in the following image.
You can save the report layout as a template for subsequent use in other applications. For this, click the report’s smart tag, and in the invoked Report Tasks list, select the Save… link.
Steps 16-17. Display the Report
Use the following code in your application to create a report at runtime, bind it to the Scheduler control and invoke the Preview dialog.
using DevExpress.XtraReports.UI; using DevExpress.XtraScheduler; using DevExpress.XtraScheduler.Reporting; XtraSchedulerReport1 xr = new XtraSchedulerReport1(); SchedulerControlPrintAdapter scPrintAdapter = new SchedulerControlPrintAdapter(this.schedulerControl1); xr.SchedulerAdapter = scPrintAdapter; xr.CreateDocument(true); using (ReportPrintTool printTool = new ReportPrintTool(xr)) { printTool.ShowRibbonPreviewDialog(); }
Run the application and execute the code. The report preview is shown in the image below.