Render subreport
To render a subreport in the Bold Reports® WPF Report Viewer, add the main report and the subreport to your application and set the main report path. A subreport displays another report inside the body of a main report. The following steps help you customize subreport properties such as data source, report path, and parameters.
-
Add the sub report and main reports to your application
Resourcesfolder. In this tutorial, using the already created reports. Refer to the Create RDL Report section or Create RDLC Report section for creating new reports.Download the
side-by-side-main-report.rdl,side-by-side-sub-report.rdlreports from the subreport samples download. Also, you can add the report from Syncfusion® installation location. For more information, see Samples and demos. The reports used from installed location, requiresNorthwindIO_Reports.sdfdatabase to run, so add it to your application. -
Set the main report path
ReportPathproperties of the Report Viewer as in following code snippet.
this.reportViewer.ReportPath = System.IO.Path.Combine(Environment.CurrentDirectory, @"Resources\side-by-side-main-report.rdl");
this.reportViewer.RefreshReport();How do I load a subreport as a stream?
To load a subreport as a stream in the WPF Report Viewer, set the subreport stream in the LoadSubreport method of the Report Viewer, as in the following code snippet:
FileStream subReportStream = new FileStream(System.IO.Path.Combine(Environment.CurrentDirectory, @"Resources\product-list.rdlc"), FileMode.Open, FileAccess.Read);
FileStream mainReportStream = new FileStream(System.IO.Path.Combine(Environment.CurrentDirectory, @"Resources\product-list-main.rdlc"), FileMode.Open, FileAccess.Read);
this.reportViewer.SubreportProcessing += (sen, arg) =>
{
arg.DataSources.Clear();
arg.DataSources.Add(new BoldReports.Windows.ReportDataSource { Name = "list", Value = ProductList.GetData() });
};
this.reportViewer.LoadSubreport("product-list", subReportStream);
this.reportViewer.LoadReport(mainReportStream);
this.reportViewer.RefreshReport();
.....
public class ProductList
{
public string ProductName { get; set; }
public string OrderId { get; set; }
public double Price { get; set; }
public string Category { get; set; }
public string Ingredients { get; set; }
public string ProductImage { get; set; }
public static IList GetData()
{
List<ProductList> datas = new List<ProductList>();
ProductList data = null;
data = new ProductList()
{
ProductName = "Baked Chicken and Cheese",
OrderId = "323B60",
Price = 55,
Category = "Non-Veg",
Ingredients = "grilled chicken, corn and olives.",
ProductImage = ""
};
datas.Add(data);
data = new ProductList()
{
ProductName = "Chicken Delite",
OrderId = "323B61",
Price = 100,
Category = "Non-Veg",
Ingredients = "cheese, chicken chunks, onions & pineapple chunks.",
ProductImage = ""
};
datas.Add(data);
data = new ProductList()
{
ProductName = "Chicken Tikka",
OrderId = "323B62",
Price = 64,
Category = "Non-Veg",
Ingredients = "onions, grilled chicken, chicken salami & tomatoes.",
ProductImage = ""
};
datas.Add(data);
return datas;
}
}