Hello there. I have been racking my brain and pulling what hair I have left for the past couple of days and am hoping someone can assist me.
I want to apply a new subreport to my RDLC main report. The main report populates fine using a programmatically created dataset created from within the form containing the reportviewer.
That works a treat. What I now want to do is to create a subreport and add it to a table column in the main report.
There are 2 datasets, one called Phases ( used in the Main report with primary keys quoteNo,quoteSuffix, quoteType) and the other calledPhaseLines (used in the SubReport with primary keys quoteNo,quoteSuffix, quoteType & phaseNo ).
I simply want the subreport to show all the lines within each phase shown on the Main report.
So I created a subreport with 4 parameters ( quoteNo,quoteSuffix, quoteType & phaseNo ) and a dataset for PhaseLines.
I fully understand that I need to create a SubreportProcessingEventHandlerwhich will add the datasource.
But I don't know how to utilise the subreport's parameters in order to populate the subreport's dataset as I won't know whatphaseNo I'm currently at.
I want to populate the subreport from within the code. Can anyone kindly assist me and point me in the right direction.
Here's a snippet of my code :
private void Form1_Load(object sender, EventArgs e)
{
LoadMainReport(quoteNo, quoteSuffix, quoteType);
mainReportViewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(SetSubDataSource);
this.mainReportViewer.RefreshReport();
}
private void LoadMainReport(string quoteNo, string quoteSuffix, string quoteType)
{
mainReportViewer.Visible = true;
mainReportViewer.LocalReport.ReportPath = @"c:\users\abdullah.arshad\Documents\CharconDev\VISUAL STUDIO PROJECTS\TestSubReportApp\TestSubReportApp\Reports\MainReport.rdlc";
DataTable phasesDT = csData.GetPhaseNumbersTable(quoteNo, quoteSuffix, quoteType);
DataSet phasesDS = new DataSet("phases");
phasesDS.Tables.Add(phasesDT);
ReportDataSource rds = new ReportDataSource("PhasesDataSet", phasesDS.Tables[0]);
mainReportViewer.LocalReport.DataSources.Clear();
mainReportViewer.LocalReport.DataSources.Add(rds);
this.mainReportViewer.RefreshReport();
}
private void SetSubDataSource(object sender, SubreportProcessingEventArgs e)
{
string phaseNo = (e.Parameters["phaseNo"].Values.First()).ToString();
DataTable phaseLinesDT = csData.GetPhaseCostLinesDT(quoteNo, quoteSuffix, quoteType, phaseNo);
e.DataSources.Add(new ReportDataSource("PhaseLinesDataSet", phaseLinesDT)); ;
}
Many thanks in advance.
Abdullah