Quick Start

Learn how to create a simple report application using the WinForms FlexReport control. Follow the steps below to get started:

Create a Report Definition

You can create report definitions using the FlexReport Designer application (with zero code) as well as programmatically. The easiest way to create a report definition using the FlexReportDesigner app, which is a stand-alone application similar to the report designer in Microsoft Access and Crystal Reports.

Note: The C1FlexReportDesigner.exe for 64-bit platform and C1FlexReportDesigner32.4.exe for 32-bit platform are located at C:\Program Files (x86)\ComponentOne\Apps\v4.5.2 on your computer.

FlexReportDesigner provides the FlexReport Wizard, a report engine to create reports. With this wizard, you can choose a suitable data source, select fields, layouts and style etc.

To begin, complete the following steps:

  1. Run the C1FlexReportDesigner.exe file.
  2. Go to File menu in the menu bar and select the New command to create a new empty report definition file.
  3. Click New Report dropdown from the Reports tab located on the extreme left of designer and select Report Wizard.
    Select Report Wizard

    The FlexReport Wizard opens.

    Report Wizard

    Here, we have used 'OLEDB Data Provider' as the data provider. You can also choose any other data provider from the drop-down button.

    Add a DataSource to Report

    Using the FlexReport Wizard, complete the following steps to add a data source in the new report:

    1. Click the ellipsis button to bring up the standard connection string builder. The Data Link Properties dialog box opens.
      Small window with link provider for data
    2. Select the Provider tab and select a data provider from the list. For this example, select Microsoft Jet 4.0 OLE DB Provider.
    3. Click the Next button or select the Connection tab. Now, you must choose a data source.
    4. Click the ellipsis button to select a database. The Select Access Database dialog box appears. For this example, select the C1NWind.mdb located in the Common folder in the ComponentOne Samples directory (by default installed in the Documents folder). Note that this directory reflects the default installation path and its path may be different if you made changes to the installation path.
      Small window with option to provide database name
      You can test the connection and click OK.
    5. Click OK to close the Data Link Properties dialog box.
    6. Once you have selected your data source, you can select a table, view, or stored procedure to provide the actual data.Click Next.
    7. Select the Data source tab and select the Products table from the Tables list.
      Select the Data Source for the new report.

    Select Data Fields

    1. Select the fields you want to include in the report using the FlexReport Wizard.
      Small window with option to select fieldsThis page in the Wizard contains a list of fields available from the recordset you selected, and the two lists that define the group and detail fields for the report. Group fields define how the data will be sorted and summarized, and Detail fields define what information you want to appear in the report.
      You can move fields from one list to another by dragging them with your mouse pointer. Drag fields into the Detail list to include them in the report, or drag within the list to change their order. Drag fields back into the Available list to remove them from the report. With your mouse pointer, select the CategoryID field and drag it into the Groups list.                                                   
    2. Press the >> button to move the remaining fields into the Detail list.
      Selecting Fields in FlexReport WizardClick Next.                             

    Select Layout and Style

    1. Select the layout for the new report. FlexReport Wizard lets you select data layouts, page orientation and choose to adjust fields to fit the page. Keep the Outline layout.
      Selecting Layout in FlexReport Wizard
    2. Click Next.
    3. Select the style for the new report. The FlexReport Wizard lets you to select the fonts and colors that will be used in the new report.
      Selecting Style in FlexReport Wizard
    4. Click Next.

    Add Title and Preview the Report

    1. Select a title for the new report.
      Enter a title for the new report, Products Report, for example.
      Enter Title in FlexReport Wizard
    2. Choose Preview the report option and click Finish. You will immediately see the report in the preview pane of the Designer.
      Window that previews the report
Note: You can invoke the FlexReportDesigner from Visual Studio as well. To do so, complete the following steps:
  1. Create a .NET project and add the FlexReport component to your Toolbox.
  2. From the Toolbox, double-click the FlexReport icon to add the component to your project. Note that the component will appear below the form in the Component Tray.
  3. Click the FlexReport component's smart tag and select Edit Report from its Tasks menu.
    The FlexReportDesigner opens and the C1FlexReport Wizard is ready to guide you through the five easy steps discussed above.

Modify the report

With the FlexReportDesigner in preview mode, you cannot make any adjustments to the report. Click the Design button to switch to Design mode and begin making modifications. The right pane of the main window switches from Preview mode to Design mode, and it shows the controls and fields that make up the report.

For this example, we will resize the Group Header section and fields as well as format a field value. To do this, complete the following steps:

  1. To resize the Group Header section, select its border and with your mouse pointer drag to the position where you want it.
    Resize group header section.
  2. With your mouse pointer, drag the handles in the field corners to resize fields.
    Drag the handles in the field corners to resize fields.
    Tip: If the text is not fitting in the field, set the Appearance.WordWrap property for the field to True in the Properties window.
  3. In the Properties window, select the UnitPriceLbl field in Detail section under the Unit Price column.
  4. Set the Appearance.Format property for the field to Currency.

    Modify FlexReport Appearance from Properties Pane

  5. Click the Preview button to switch to Preview mode and see your modifications.
  6. Click Design button to switch from Preview mode to Design mode.
  7. Click the File menu and select Save As from the menu that appears.

    Save FlexReport Definition

  8. In the Save Report Definition File dialog box, enter ProductsReport.flxr in the File name box. Save the file to a location that you will remember for later use.
  9. Close the Designer and return to your Visual Studio project.

You have successfully created a report definition file; in the next step you will load the report in the C1FlexReport component.

Load and render the report

To load a report definition from a file at design time, complete one of the following tasks:

Using the Load Report dialog box, select the report you want and complete the following tasks:

  1. Click the ellipsis button. The Open dialog box appears.
  2. Browse to the location that you just saved your Products Report.flxr file, select it, and click Open.
  3. The available report definitions are listed in the Report drop-down box. Select the Products Report definition to load.
  4. Click Load and OK to close the dialog box.
    Loading report in the C1FlexReport Component.

You can also load a report definition from a file via code. For this purpose, double-click the form and enter the following code in the Form1_Load event handler:

C#
Copy Code
private void Form1_Load(object sender, EventArgs e)
{   // Creates a resource manager.
    ComponentResourceManager resources = new ComponentResourceManager(typeof(Form1));
    // Get the resource string that stores the report definition.
    c1FlexReport1.ReportDefinition = resources.GetString("c1FlexReport1.ReportDefinition");
    // Sets the report name.
    c1FlexReport1.ReportName = "Products Report";
}

In the next step you will render the report into a preview control.

Once the report definition has been created, the data source defined and loaded into the FlexReport component, you can render the report to the printer to the preview control 'FlexViewer', or export to different file formats.

To preview the report in the FlexViewer control, the steps are as follows:

  1. From the Toolbox, double-click the FlexViewer control to add it to your project.
  2. From the Properties window, set the FlexViewer.Dock property to Fill.
  3. Select the Windows Form with your mouse and drag the corners to resize it.
  4. Double-click the form and enter the following code in the Form1_Load event handler:
    C#
    Copy Code
    private void Form1_Load(object sender, EventArgs e)
    {
        //load report definition
        c1FlexReport1.Load(@"..\..\Products Report.flxr", "Products Report");
        //preview the report
        c1FlexViewer1.DocumentSource = c1FlexReport1;
    }
    
  5. Press F5 to run the code. Observe the output. It looks as shown below:

    Display report in FlexViewer.

    Note: WinForms .NET 6 Edition does not include rich design-time support yet. We will enhance it in the future releases.