views:

31

answers:

1

Hi, I have the report with lots of sub-reports within.

How can I walk through the collection of sub-reports in main report? I need this to change the data source for each sub report.

TIA

+1  A: 

Edited per CodeByMoonlight comment - I haven't tested this yet, but it should be way better than my original.

ReportDocument reportDocument = new ReportDocument();
reportDocument.Load(...);
foreach (ReportDocument subreportDocument in reportDocument.Subreports) {   
  // do something here
} 
Ray
Slightly overkill - there's a SubReports property of the ReportDocument itself, so you don't need to enumerate every single report object and check it's a subreport.
CodeByMoonlight
@moonlight - thanx - that looks much better. My original was code I had been using for years - I wonder if the Subreports property is fairly new, or if I just missed it first time around...
Ray
Much better :) I think it's been there a while, but I've not had call to use it much.
CodeByMoonlight