reportViewer.LocalReport.SubreportProcessing. How do i clear previous handlers?

C

Claire

Hi

I've a class that contains methods to set up several reports. The reports
are all different views of the same data set, so it seemed logical to have a
class to generate the dataset just once and provide methods to deliver each
report as it's needed.
The report used by the following function has a single subreport. I set up
an event handler for when the subreport needs to be built.

My worry is, if the same reportviewer control is passed into the function,
is it accumulating a stack of reportviewer.localreport.SubreportProcessing
event handlers somewhere?
I considered adding reportViewer.LocalReport.SubreportProcessing -=
DailySubreportProcessingEventHandler; at the end, but reports are rendered
asynchronously so this wasn't a good solution
If event handlers are stacking then how do I clear the list before adding a
new event handler please


public void DailyReport(Int64 userID, Int32 siteID,
DateTime StartDate, DateTime EndDate, ReportViewer reportViewer)
{
const string fnName = "DailyReport";
try
{
CreateDatasets(userID, siteID, StartDate, EndDate);

// Localize the reports
string ReportPath =
ReportHandler.LocalizeAndWriteReportToFile("rptDaily.rdlc");
ReportHandler.LocalizeAndWriteReportToFile("rptDaily_SubReport.rdlc");

// Set up the report viewer
reportViewer.LocalReport.DataSources.Clear();
reportViewer.LocalReport.ReportPath = ReportPath;
reportViewer.LocalReport.SubreportProcessing +=
DailySubreportProcessingEventHandler;

// Set up report datasource for the repors for users
ReportDataSource rds = new ReportDataSource {Name =
"datasetResults_dtUsers", Value = usersTable};
reportViewer.LocalReport.DataSources.Add(rds);

// Set up report datasource for the report for results
rds = new ReportDataSource {Name = "datasetResults_dtResults", Value
= resultsTable};
reportViewer.LocalReport.DataSources.Add(rds);

// Reload the report into the viewer
reportViewer.RefreshReport();

}
catch(Exception e)
{
LogException(fnName, e);
throw;
}
#endregion
}// function

private void DailySubreportProcessingEventHandler(object sender,
SubreportProcessingEventArgs e)
{
e.DataSources.Add(new ReportDataSource("datasetResults_dtResults",
resultsTable));
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top