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
- Start Microsoft Visual Studio 2012, 2013, 2015, 2017 or 2019, and create a new Windows Forms application or open an existing application.
- Drop the SnapControl from the DX20.2: Reporting Toolbox tab on the application’s main form.
Next, open the PROJECT menu and click the Add New Data Source… command.
Select Database.
Select Dataset to specify the type of the database model..
Select the nwind database. By default, it is stored in the following folder: C:\Users\Public\Documents\DevExpress Demos 20.2\Components\Data.
The final wizard page allows you to choose which tables to obtain from the database. After this step, click Finish.
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.