Skip to main content

Create a Side-by-Side Report

  • 3 minutes to read

This tutorial describes the steps required to create a report that shows two subreports side-by-side, at design time within Visual Studio. Each subreport displays information about a selected employee, providing a convenient way to put employee resumes together. You can use a similar approach to show two completely different reports (which use different data sources) within a single report document.

HowTo - SideBySideReport_2

Tip

To get started with this tutorial, open an existing reporting application or create a new application (the Add a Report to Your .NET Application section explains how to create a reporting application on different platforms).

Create a Detail Report

  1. To create a detail report in this tutorial, start with a report (named detailReport1) that is bound to the “Employees” table of the sample Northwind database (the nwind.mdb[1] file included in the XtraReports installation). To learn more about binding a report to a data source, see Provide Data to Reports.
  2. Decrease the detail report’s right margin, so that two reports will fit into the width of the master report.

    HowTo - SideBySideReport_0

  3. Drop the required data fields from the Field List onto the report’s Detail band and adjust the layout accordingly.

    HowTo - SideBySideReport_1

    You can use the mail merge feature to make a control show both static and dynamic content, or to bind a control to several data fields simultaneously.

Create a Side-by-Side Report

  1. Add another report to the application (named masterReport) that will show the detail reports side-by-side.
  2. Open your report in the Visual Studio Designer and press CTRL+ALT+X to run the Toolbox. Expand the DX.22.1: Report Controls category and drop two XRSubreport controls onto the report’s Detail band.

    HowTo - SideBySideReport_1a

  3. For both subreports, set the SubreportBase.ReportSource property to detailReport1.

    HowTo - SideBySideReport_1b

  4. To apply the changes, select BUILD | Rebuild Solution in the main menu of the project.

    Shared_RebuildSolution

  5. To select an employee for each subreport, handle the subreports’ BeforePrint event in the following way.

    using System.Drawing.Printing;
    using DevExpress.XtraReports.UI;
    // ...
    
    private void xrSubreport1_BeforePrint(object sender, PrintEventArgs e) {
        ((XRSubreport)sender).ReportSource.FilterString = "[EmployeeID] = 1";
    }
    
    private void xrSubreport2_BeforePrint(object sender, PrintEventArgs e) {
        ((XRSubreport)sender).ReportSource.FilterString = "[EmployeeID] = 2";
    }
    

Your report is now ready to be generated. In Visual Studio, you can view the report by switching to the Preview tab.

Footnotes
  1. If your project in Visual Studio 2022 has to connect to Microsoft Access databases, note that Visual Studio 2022 is a 64-bit process, and Microsoft OLE DB Provider for Jet and the Jet ODBC driver are only available in 32-bit versions. It is recommended that you use the 64-bit Microsoft Access Database Engine (Access Connectivity Engine, ACE), or use an earlier version of Visual Studio (VS 2019) that supports 32-bit database providers. For more information, review the following article: Connect to data in an Access database.