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:

Steps 1-3. Add a Scheduler Report to the Application

  1. Open the project that contains the SchedulerControl in the Microsoft Visual Studio Designer.
  2. In the PROJECT menu, select Add DevExpress Item -> New Item... to invoke the DevExpress Template Gallery dialog. Select the Scheduler Report template.

    Reporting - Select Scheduler Report template

  3. 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.

    Reporting - Empty Designer

Steps 4-6. Load a Report from a Template

NOTE

To create a report from scratch, skip to Step 7.

  1. 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.

    Report Templates Load

  2. 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.

    Report Templates

  3. The selected report is immediately loaded into the Visual Studio designer.

    Report Templates 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.

  1. To proceed with report creation, open the Toolbox pane (by pressing CTRL+ALT+X). Then, select the DayViewTimeCells control in the DX.20.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.

    SchedulerReporting - Drop DayViewTimeCells

    NOTE

    The current implementation requires that report controls reside in the DetailBand only, and not in the other report bands.

  2. Add the HorizontalResourceHeaders control. Place it above the DayViewTimeCells control in the Detail Band.
  3. Add the HorizontalDateHeaders control. Place it above the HorizontalResourceHeaders control.
  4. Use the HorizontalResourceHeaders control's smart tag menu to link it to the HorizontalDateHeaders control.
  5. Use the DayViewTimeCells control's smart tag menu to link it to the HorizontalResourceHeaders control, as shown in the image below.

    SchedulerReporting - DayViewTimeCells smart tag

  6. 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.

    SchedulerReporting - DayViewTimeRuler smarttag

  7. 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.

    SchedulerReporting - TimeRuler Alignment

  8. 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.

    SchedulerReporting - Resulting Report in Designer

  9. 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.

    SchedulerReporting PageBreak AfterBand

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.

Report Templates Save

Steps 16-17. Display the Report

  1. 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();
                }
    
  2. Run the application and execute the code. The report preview is shown in the image below.

    SchedulerReporting - Result

See Also