绑定对象与List<>到水晶报告 [英] Binding object with List<> to Crystal Report
问题描述
我有一个类包含一些属性,包括一个List<>的子对象。
I have a class that contains a few properties including one that is a List<> of children objects.
简单示例:
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() { ... }
}
试图绑定此对象(在示例中的发票)到水晶报表(使用VS2008水晶报表设计器),而我得到的简单属性(名称,CreatedDate)显示在字段资源管理器中的子集合不。我试过使用一个ArrayList(建议(如何使用强类型列表作为Crystal Reports的数据生成)但是不起作用。
推荐答案
在进行一些搜索和实验之后,我试图将报表绑定到包含子集合的自定义对象失败,而不是使用.Net对象我使用XSD shema和运行时设计了报表生成一个xml文件,并将成本报表的数据源设置为使用.ReadXML方法构建的DataSet。
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);
这篇关于绑定对象与List<>到水晶报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!