The requested page is not available for the requested platform. You are viewing the content for Default platform.

Create a Report in Visual Studio

  • 5 min to read

In this lesson, you will learn how to create reports in the integrated reporting system. This system is based on the DevExpress Reporting library for WinForms and ASP.NET. This lesson will guide you through creating a report that shows a list of Contact objects with their names and email addresses. Report will be available to end-users in both WinForms and ASP.NET applications.

Adding XAF Modules

  • Add the platform-independent Reports V2 module to your project. To do this, double-click the Module.cs (Module.vb) file in the MySolution.Module project. This will invoke the Module Designer. In the Toolbox, navigate to the DX.19.1: XAF Modules group. Drag the ReportsModuleV2 item from this group to the Designer's Required Modules section.

    ReportsV2_to_Module_cs

  • Add a WinForms-specific Reports V2 module to your WinForms module project. Double-click the WinModule.cs (WinModule.vb) file in the MySolution.Module.Win project. This will invoke the Module Designer. In the Toolbox, navigate to the DX.19.1: XAF Modules group. Drag the ReportsWindowsFormsModuleV2 item from this group to the Designer's Required Modules section.

    ReportsV2_to_WinApp_cs

  • Add the ASP.NET-specific Reports V2 module to your ASP.NET application project. Invoke the Module Designer by double-clicking the WebModule.cs (WebModule.vb) file in the MySolution.Module.Web project. In the Toolbox, navigate to the DX.19.1: XAF Modules group. Drag the ReportsAspNetModuleV2 item from this group to the Designer's Required Modules section.

    ReportsV2_to_WebApp_cs

  • Rebuild your solution.

If you are using eXpress Persistent Objects as your ORM, proceed to the next section (Design-Time Reporting) section. Otherwise, if you use Entity Framework Code First, execute the following steps.

  • Register the ReportDataV2 type in the DbContext as shown in the Set a Many-to-Many Relationship (EF) lesson.
  • Double-click the MySolution.Win\WinApplication.cs file to invoke the Application Designer. In the Modules pane, focus the ReportsModuleV2 component. In the Properties window, set the ReportsModuleV2.ReportDataType property to DevExpress.Persistent.BaseImpl.EF.ReportDataV2.
  • Repeat the previous step for the MySolution.Web\WebApplication.cs file.

Design-Time Reporting

  • Right-click the MySolution.Module project and select Add | New Folder. Set the name of the new folder to "Reports". Right-click the Reports folder and select Add | New Item.

    New_Report

    Note

    You can place reports in any folder (including the root project folder), although it is recommended that you organize your project files.

  • Select the DevExpress v19.1 Report Wizard, name it "ContactsReport" and click Add.

    New_Report_Dialog

  • This invokes the Report Wizard. Select Empty Report and click Finish.

    XtraReport_Wizard

    Note

    Do not use report types other than Empty Report. Other report types will not allow you to select an XAF-specific data source. You will be able to proceed with the Report Wizard later, after the data source is selected in the Report Designer.

  • After clicking Finish, the Report Designer is invoked. In the Toolbox, navigate to the DX.19.1: XAF Data Sources for Reports group. Drag the CollectionDataSource item from this group to the Report Designer window.

    CollectionDataSource_to_Report

  • In the Report Explorer window, select the collectionDataSource1 item. In the Properties window, assign the "MySolution.Module.BusinessObjects.Contact" value to the ObjectTypeName property. Note the changes in the Field List window - the fields of the Contact class are now available if you expand the collectionDataSource1 node.

    DataSource_Populate

  • Click the Report Designer's Smart Tag and select Design in Report Wizard... in the invoked menu.

    Report_Designer-Smart_Tag

  • This invokes the Report Wizard. In the first step, you should select the Data-bound Report and click Next. Since the data source is already specified, you will skip some wizard screens and the second step will allow you to choose the report data.

    Report_Designer0

  • Select the fields that will be used within your report. Move the following fields from the Available fields list to the Selected fields list.

    • FirstName
    • LastName
    • Email

    To move a field, select it and click the arrow button (>). Click Next when finished.

    Report_Wizard_1

  • In the second step, you can select the fields by which to group the report rows. Since grouping is not required in this example, click Next to continue.

    Report_Wizard_2

  • In the next step, you can customize the report layout. Select the Tabular layout and click Next.

    Report_Wizard_3

  • You can customize the report appearance in the next step. Select the Casual style and click Next.

    Report_Wizard_4

  • In the final step, you can set the report's title. This text will be displayed at the top of your report. Set the title to "Contacts" and click Finish.

    Report_Wizard_5

  • The report structure you created will be displayed in the Report Designer. Save the report.

    Report_Structure

    Note

    At design time, the Preview tab of the Report Designer is empty. The CollectionDataSource and ViewDataSource components do not connect to a database directly and require an IObjectSpace instance (that can be created at runtime only) to load data. Thus, it cannot load data at design time.

  • Now register the report within your XAF application using the PredefinedReportsUpdater class. To do this, in the Solution Explorer, right-click the MySolution.Module | Module.cs (Module.vb) file and select View Code to edit its source code. The code snippet below demonstrates the required changes.

    using DevExpress.ExpressApp.ReportsV2;
    using MySolution.Module.Reports;
    using MySolution.Module.BusinessObjects;
    //...
    namespace MySolution.Module {
        public sealed partial class MySolutionModule : ModuleBase {
            //...
            public override IEnumerable<ModuleUpdater> GetModuleUpdaters(
                IObjectSpace objectSpace, Version versionFromDB) {
                ModuleUpdater updater = new DatabaseUpdate.Updater(objectSpace, versionFromDB);
                PredefinedReportsUpdater predefinedReportsUpdater = 
                    new PredefinedReportsUpdater(Application, objectSpace, versionFromDB);
                predefinedReportsUpdater.AddPredefinedReport<ContactsReport>(
                "Contacts Report", typeof(Contact));
                return new ModuleUpdater[] { updater, predefinedReportsUpdater };
            }
            //...
        }
    }
    
  • Run the WinForms or ASP.NET application, navigate to Reports and open the Contacts Report.

    ReportV2_OK

    ReportV2_Web_OK

Note
  • Predefined reports are not editable at runtime, but you can edit a copy of a report (see Modify an Existing Report).
  • Report data can be sorted and filtered according to a parameter defined by the end-user.

Next Lesson: Create a Report at Runtime

See Also