Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binding object with List<> to Crystal Report

I have a class that contains a few properties including one that is a List<> of children objects.

Simple Example:

    public class LineItem
    {
       public string Name { get; set; }
       public decimal Amount { get; set; }
    }

    public class Invoice
    {
       public string Name { get; set; }
       public DateTime CreatedDate { get; set; }
       public List<LineItem> LineItems { get; set; }
       public Invoice() { ... }
    }

I am trying to bind this object (Invoice in the example) to a Crystal Report (using VS2008 crystal report designer) and while I get the simple properties (Name, CreatedDate) to show up in Field Explorer the child collection does not. I have tried using an ArrayList (as suggested ( How can I use strongly typed lists as the datasoruce for a Crystal Reports ) but that did not work.

like image 976
jwarzech Avatar asked May 19 '10 21:05

jwarzech


1 Answers

After a bit of searching and experimenting I was unsuccessful in attempting to bind the report to a custom object that contained a child collection. Instead of using a .Net object I designed the report using a XSD shema and at runtime generated an xml file and set the cost report's datasource to a DataSet that I built using the .ReadXML method.

var exportData = new XDocument(....);
var dataSet = new System.Data.DataSet();
dataSet.ReadXml(exportData.CreateReader());

var report = new ReportDocument();
report.Load("...");
report.SetDataSource(data);
like image 174
jwarzech Avatar answered Sep 30 '22 20:09

jwarzech