[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Collapse]Reporting
 [Expand]Product Information
 [Expand]Get Started with DevExpress Reporting
 [Expand]Create Popular Reports
 [Collapse]Detailed Guide to DevExpress Reporting
   Introduction to Banded Reports
  [Expand]Provide Data to Reports
  [Expand]Use Report Controls
  [Expand]Shape Report Data
   Arrange Dynamic Report Contents
  [Expand]Customize Appearance
  [Expand]Add Navigation
  [Expand]Provide Interactivity
  [Expand]Add Extra Information
  [Expand]Merge Reports
  [Expand]Use Expressions
  [Expand]Store and Distribute Reports
  [Collapse]Reporting API
   [Collapse]Create Reports in Code
     Create a Simple Static Report (Runtime Sample)
     Create a Master-Detail Report (Runtime Sample)
     Create a Cross-Tab Report (Runtime Sample)
     Report Class Hierarchy
     Report Events
   [Expand]Use Report Scripts
 [Expand]Visual Studio Report Designer
 [Expand]Create End-User Reporting Applications
 [Expand]API Reference
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Create a Master-Detail Report (Runtime Sample)

This tutorial demonstrates the main needed steps to create a data-aware report in code.

Expanded Add Required References and Create a Report

The following code creates a master-detail report and displays its Print Preview.

To use this code in your application, include all necessary libraries in the References list of the project.

Expanded Bind the Report to Data

The following code creates a SqlDataSource with a master-detail relation and binds the report to it.

To learn how to bind your report to other data source types, see Providing Data to Reports.

Expanded Create a Master Report Section

The following code creates content for the master section of the report.

In particular, it adds a ReportHeaderBand and DetailBand to the collection of report bands and adds various report controls to these bands.

The label (see XRLabel) placed onto the Report Header displays static text, and the label placed onto the Detail band is bound to the "CategoryName" field from the report's data source.

To provide data to report controls, use the XRControl.ExpressionBindings or XRControl.DataBindings property depending on the report's data binding mode.

Expanded Create a Detail Report Section

The following code creates a detail section in the report.

Next, it creates new Report Header and Detail bands at the detail level and adds a table control to each of these bands.

The cells of the table placed in the Detail band are bound to the relational table of the report's data source. This table is assigned different styles for displaying odd and even rows from the data source.

The width of both tables equals the effective page width of the report.

Expanded Preview and Publish the Report

The following code illustrates the easiest approach to publish reports in a desktop application (WinForms or WPF).

Is this topic helpful?​​​​​​​