How to: Create a Master-Detail Report

  • 2 minutes to read

This tutorial describes the steps used to create a master-detail report, i.e., a report that is displays data from a hierarchical datasource.

Follow these steps to create a master-detail report.

Connect to a Datasource

  1. Start Microsoft Visual Studio 2012, 2013, 2015, 2017 or 2019, and create a new Windows Forms application or open an existing application.
  2. Drop the SnapControl from the DX20.1: Reporting Toolbox tab on the application's main form.
  3. Next, open the PROJECT menu and click the Add New Data Source... command.

    How-to-Create-Master-Detail-Report-01

  4. Select Database.

    How-to-Create-Master-Detail-Report-02

  5. Select Dataset to specify the type of the database model..

    How-to-Create-Master-Detail-Report-03

  6. Select the nwind database. By default, it is stored in the following folder: C:\Users\Public\Documents\DevExpress Demos 20.1\Components\Data.

    How-to-Create-Master-Detail-Report-04

  7. The final wizard page allows you to choose which tables to obtain from the database. After this step, click Finish.

    How-to-Create-Master-Detail-Report-05

  8. To connect the application to data, handle the Load event of the application's main form and write the following code in the event handler.

    
    using System;
    using System.Data.OleDb;
    using System.Windows.Forms;
    using Master_Detail_Report.nwindDataSetTableAdapters;
    // ...
    
    private void Form1_Load(object sender, EventArgs e) {
        string path = 
    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\Public\\Documents\\DXperience 12.2 Demos\\Data\\nwind.mdb";
        var dataSource = new nwindDataSet();
        var connection = new OleDbConnection();
        connection.ConnectionString = string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}", path);
    
        var products = new ProductsTableAdapter();
        products.Connection = connection;
        products.Fill(dataSource.Products);
    
        var order_details = new Order_DetailsTableAdapter();
        order_details.Connection = connection;
        order_details.Fill(dataSource.Order_Details);
    
        var bindingSource = new BindingSource();
        bindingSource.DataSource = dataSource;
        bindingSource.DataMember = "Products";
        snapControl1.Document.DataSource = bindingSource;
    }
    

Arrange the Content

Run the Master-Detail Report to create it.

You can easily arrange the content of the report by dropping fields from the Field List window onto the report's text editing surface.

How-to-Create-Master-Detail-Report-06