I searched the Reporting forums for any example I could find about combining multiple reports together in to one report, sadly I found none what so ever. Yes there were mentions of using sub reports, but what if you had more than one report you wanted to add in there. There was no examples at all that I could find. So I sat down and started hacking away at this problem. Luckily I did find a solution that works. I hope this helps out anyone that read this, enjoy. There may be some errors here and there, as there always are in examples. But the general idea should be straight forward. Also that only the detail section of each report will be placed in the sub report at the current moment. Thank you for your time.
PageBatch.cs
TestPage.cs
PageBatch.cs
public PageBatch(List<int> ItemIds) { |
//Create new sections |
PageHeaderSection header = new PageHeaderSection(); |
PageFooterSection footer = new PageFooterSection(); |
DetailSection ds = new DetailSection(); |
//"Remove" the header and footer |
header.Height = new Unit(0.1, UnitType.Pixel); |
footer.Height = new Unit(0.1, UnitType.Pixel); |
//add header |
this.Report.Items.Add((ReportItemBase)header); |
double previousLocation = 0; //this will store the offset of the Y direction |
UnitType pageMeasurementType = this.PageSettings.PaperSize.Width.Type; |
for(int i = 0; i < ItemIds.Count; i++){ |
//since subReport inherits from baseitem it can be fed in programmaticly |
SubReport sb = new SubReport(); |
sb.ReportSource = new TestPage(ItemIds[i]); |
//move subreport 1.25 inches in Y direction |
sb.Location = new PointU(new Unit(0, pageMeasurementType), new Unit(previousLocation, pageMeasurementType)); |
sb.Width = this.PageSettings.PaperSize.Width - (this.PageSettings.Margins.Right + this.PageSettings.Margins.Left ); |
previousLocation += this.PageSettings.PaperSize.Height.Value; |
ds.Items.Add(sb); |
} |
this.Report.Items.Add((ReportItemBase)ds); |
this.Report.Items.Add((ReportItemBase)footer); |
this.Report.PageSettings.Margins.Top = new Unit(0.15, UnitType.Inch); |
this.Report.PageSettings.Margins.Bottom = new Unit(0.25, UnitType.Inch); |
this.Report.PageSettings.Margins.Left = new Unit(0.25, UnitType.Inch); |
this.Report.PageSettings.Margins.Right = new Unit(0.25, UnitType.Inch); |
} |
TestPage.cs
public TestPage(int _ItemId) { |
//do some logic here |
} |