Example T262615
Visible to All Users

Reporting for WinForms - Master-Detail Report with a Subreport

This example shows the master-detail report created with the XRSubreport control and illustrates the following help topic: Create a Master-Detail Report with a Subreport.

Screenshot - Master-Detail Report with a Subreport

Files to Review

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

dxSampleMasterDetailSubreport/Form1.cs(vb)
C#
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace dxSample { public partial class Form1 : DevExpress.XtraBars.ToolbarForm.ToolbarForm { public Form1() { InitializeComponent(); } private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { barButtonItem2.Down = false; var report = new MasterReport(); report.CreateDocument(); this.documentViewer1.DocumentSource = report; } private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { barButtonItem1.Down = false; var report = new MasterReportOne(); report.DataSource = CategoryProductDataSource.GetData(); report.CreateDocument(); this.documentViewer1.DocumentSource = report; } } }
dxSampleMasterDetailSubreport/MasterReportOne.cs(vb)
C#
using DevExpress.XtraReports.UI; using System; using System.Collections; using System.ComponentModel; using System.Drawing; namespace dxSample { public partial class MasterReportOne : DevExpress.XtraReports.UI.XtraReport { public MasterReportOne() { InitializeComponent(); } private void xrSubreport1_BeforePrint(object sender, CancelEventArgs e) { var category = GetCurrentRow() as Category; ((XRSubreport)sender).ReportSource.DataSource = category.Products; } } }
dxSampleMasterDetailSubreport/CategoryProductDataSource.cs(vb)
C#
using System.Collections.Generic; public class Category { public int CategoryId { get; set; } public string CategoryName { get; set; } public string Description { get; set; } public List<Product> Products { get; set; } } public class Product { public string ProductName { get; set; } public double UnitPrice { get; set; } } public static class CategoryProductDataSource { public static List<Category> GetData() { return new List<Category> { new Category() { CategoryName = "Beverages", Description = "Soft drinks, coffees, teas, beers, and ales", Products = new List<Product> { new Product{ ProductName = "Chai", UnitPrice = 18 }, new Product{ ProductName = "Chang", UnitPrice = 19 }, new Product{ ProductName = "Guaraná Fantástica", UnitPrice = 4.5 } }, }, new Category() { CategoryName = "Condiments", Description = "Sweet and savory sauces, relishes, spreads, and seasonings", Products = new List<Product> { new Product{ ProductName = "Aniseed Syrup", UnitPrice = 10 }, new Product{ ProductName = "Chef Anton's Cajun Seasoning", UnitPrice = 22 }, new Product{ ProductName = "Chef Anton's Gumbo Mix", UnitPrice = 21.35 }, new Product{ ProductName = "Grandma's Boysenberry Spread", UnitPrice = 25 } }, }, new Category() { CategoryName = "Confections", Description = "Desserts, candies, and sweet breads", Products = new List<Product> { new Product{ ProductName = "Pavlova", UnitPrice = 17.45 }, new Product{ ProductName = "Teatime Chocolate Biscuits", UnitPrice = 9.2 }, new Product{ ProductName = "Sir Rodney's Marmalade", UnitPrice = 81 }, new Product{ ProductName = "Sir Rodney's Scones", UnitPrice = 10 }, new Product{ ProductName = "NuNuCa Nuß-Nougat-Creme", UnitPrice = 14 }, }, } }; } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.