Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RDLC report with subreport from parent dataset?

So, I am trying to figure out how to do the following:

Imagine I have a collection of customers. It contains the following properties:

  • CustomerName
  • AccountNumber
  • TotalAmount

Now for each customer, it has a collection of invoices. Each invoice contains the following properties:

  • InvoiceNumber
  • InvoiceDate
  • AmountDue
  • Payment

I have the data retrieved from a service and stored locally. So, a collection of customers and each customer has invoices. So far so good? Pretty simple to understand!

Now, I have an RDLC and I have got it to display the collection of customers by adding the dataset, being a model from the codebase. That's all fine, binding and working and displaying the data I need.

What I am having difficulty now is how to display the list of invoices FOR THAT RECORD (the current customer).

Any ideas how to do this? I do not even know how to begin or what to use so please do not say "What have you tried?" - I do not even know where to begin, thus that question is invalid! :-)

Currently on the form I have a tablix. The tablix points to the Customer dataset (DataSet1) and the fields are added to display the property values from that dataset.

Next I need it so that either within the tablix OR something else, to take the invoices for that record and render it (with header)

I am stuck and would appreciate guidance in the right direction.

Code to render the report viewer (not that this matters at all at this point - it's the RDLC I am having difficult with):

public void RunReport<T>(List<T> reportData, List<ReportParameter> parameters, string reportLayout)
        {
            var viewer = ReportViewerHost.Child as Microsoft.Reporting.WinForms.ReportViewer;
            viewer.Reset();
            viewer.ProcessingMode = ProcessingMode.Local;
            viewer.LocalReport.ReportEmbeddedResource = "PlayPen.ReportLayouts." + reportLayout + ".rdlc";
            viewer.LocalReport.SetParameters(parameters);
            viewer.SetDisplayMode(DisplayMode.PrintLayout);
            viewer.ZoomMode = ZoomMode.PageWidth;
            viewer.LocalReport.DataSources.Clear();
            viewer.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", reportData));
            viewer.RefreshReport();
        }

Calling method:

this.reportViewer.RunReport(this.OutstandingInvoices, new List<ReportParameters>(), "OutstandingInvoices");

Thank you.

like image 934
Ahmed ilyas Avatar asked Oct 29 '22 11:10

Ahmed ilyas


1 Answers

I had the same problem. I used a subreport with a parameter between them to bind the data. I used the following guide: https://marcelwouters.wordpress.com/2011/06/01/showing-a-report-with-a-subreport-in-the-reportviewer-control-which-has-a-odata-service-as-datasource-in-a-wpf-application/

Another webpage that can give you some good points is: https://blogs.msdn.microsoft.com/sqlforum/2011/01/02/walkthrough-add-a-subreport-in-local-report-in-reportviewer/

like image 164
Josep B. Avatar answered Nov 02 '22 15:11

Josep B.