Binding object with List<> to Crystal Report

c#, crystal-reports, visual-studio-2008

Solution

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);

Problem

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.

Original source