HELP! Binding a report to Business Objects that are in a Generic List RRS feed

  • Question

  • I have a Generic List of my business object: List<Invoice>.
    Invoice contains a generic list as a property: List<InvoiceItem>.
    public class Invoice
       List<InvoiceItem> _itemList;
       public List<InvoiceItem> ItemList
          get{return _itemList;}


    I want my report to be a master detail and pass a list of invoices and have it generate an invoice per page.  I was able to get this working using the List control on the report, however, I am unable to get it to show the Item List in a table on each invoice.  I would like to have the items for each invoice on the report with the invoice.

    Please help!
    Tuesday, September 2, 2008 6:08 PM


  • Well, after much head scratching and trial and error I have discovered how to accomplish this.

    First, I create my primary report which contains everything from the master item (Invoice).  Then i created a subreport with a table on it for the InvoiceItems and the necessary report parameters.  I added the subreport to the master report and included the parameter values from the master report.  This is where things get a bit tricky.  You have to add an event handler for the LocalReport_SubreportProcessing event of the report viewer. Within the subreport I find my Invoice object within my List, which gives me access to the ItemList property of the Invoice.  I then set the datasource of the subreport to this ItemList object. The KEY here is to make sure the name of the datasource you create matches the dataset name in the subreport.
    Here's the code:

    void LocalReport_SubreportProcessing(object sender, Microsoft.Reporting.WinForms.SubreportProcessingEventArgs e)
                int invoiceId = int.Parse(e.Parameters["InvoiceId"].Values[0]);

                //Search for the invoice info in the list.
                InvoiceSummary tempIS = _invoiceList.Find(delegate(InvoiceSummary i) { return i.InvoiceId == invoiceId});

                ReportDataSource rds = new Microsoft.Reporting.WinForms.ReportDataSource("BusinessEntities_InvoiceItem", tempIS.ItemList);

    • Marked as answer by programmer84 Wednesday, September 3, 2008 5:00 PM
    Wednesday, September 3, 2008 5:00 PM