Click here to Skip to main content
16,021,288 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello there. I have been racking my brain and pulling what hair I hve left for the past couple of days and am hoping someone can assist me.
I want to apply a 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 called PhaseLines (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 SubreportProcessingEventHandler which will add the datasource.
But I don't know how to utilise the subreport's parameters in order to populate the subreport's PhaseLines dataset as I won't know what phaseNo 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 is a snippet of my code from within the form containing the reportviewer :

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
Posted
Updated 16-Jan-14 7:49am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900