Reports for WinForms | ComponentOne
Getting Started with Reports for WinForms / Getting Started with Reporting / C1Report Quick Start / Step 4 of 4: Rendering the Report
In This Topic
    Step 4 of 4: Rendering the Report
    In This Topic

    Once the report definition has been created, a data source defined, and loaded into the C1Report component, you can render the report to the printer, into preview controls, or to report files.

    To preview the report, use the use the C1Report.Document property. Assign it to the Document property in the C1PrintPreviewControl or to the .NET PrintPreview or PrintPreviewDialog controls and the preview controls will display the report and allow the user to browse, zoom, or print it.

    Note: C1Report works with the .NET preview components, but it is optimized to work with the included Reports for WinForms preview controls. When used with the included controls, you can see each report page as it is generated. With the standard controls, you have to wait until the entire report is ready before the first page is displayed.

    To complete this step:

    1. From the Toolbox, double-click the C1PrintPreviewControl icon to add the component to your project.
    2. From the Properties window, set the C1PrintPreviewControl.Dock property to Fill.
    3. Select the Windows Form with your mouse and drag to resize it. For this example, we resized the Form to 600x500 so it better reveals the preview panel.
    4. Double-click the form and enter the following code in the Form_Load event handler:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      ' load report definition
      C1Report1.Load("C:\ProductsReport.xml", "Products Report")
      ' preview the document
      C1PrintPreviewControl1.Document = C1Report1.Document
      

      To write code in C#

      C#
      Copy Code
      // load report definition
      c1Report1.Load(@"C:\ProductsReport.xml", "Products Report");
      // preview the document
      c1PrintPreviewControl1.Document = c1Report1.Document;
      

      You will need to change the directory above to the location the ProductsReport.xml file is saved.

      Note that the C1Report.Load(String, String) method has the following parameters:

      • fileName: Full name of the XML report definition file.
      • reportName: Name of the report to retrieve from the file (case-insensitive).
    5. Click the Start Debugging button to run the application. The report renders in the preview control:

    Congratulations! You just created a simple report definition, modified the report, loaded into the C1Report component, and rendered the report into a preview control. Read the following section to learn how you can further customize your report definition using VBScript expressions.