I would like to stick with one single form and ReportViewer control, and at runtime assign various reports and data sources. The diverse and complex solutions to this revealed by a quick google check prompted me to rather ask here. How can I achieve this?
I would like to stick with one single form and ReportViewer control, and at
Share
You’ll need a form featuring a ReportViewer control, RDLC reports, and data sources; there are possibly several ways of implementing this, but you can have a “report manager” class exposing methods that each display a specific report (ex.
ShowOrdersReport(),ShowTimeSheetReport(), etc.) – or you could define a baseReportBaseclass with aShow()method implementation that prompts for parameters when needed… whatever works, it will essentially boil down to this:Here you’ll want to inject the
_reportingDataSetdependency; if you’re using parameterized stored procedures, you’ll want to prompt for the report parameters before you populate the DataSet.The
ShowReport()method adds the data sources toLocalReport.DataSources, and then callsRefreshReport()which displays the report you’ve specified.