用 List<> 绑定对象到水晶报表

Binding object with Listlt;gt; to Crystal Report(用 Listlt;gt; 绑定对象到水晶报表)

本文介绍了用 List<> 绑定对象到水晶报表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含一些属性的类,其中一个是子对象的 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() { ... }
    }

我正在尝试将此对象(示例中的发票)绑定到 Crystal Report(使用 VS2008 水晶报表设计器),当我在字段资源管理器中显示简单属性(名称、CreatedDate)时,子集合没有.我尝试使用 ArrayList (如建议( 如何使用强类型列表作为 Crystal Reports 的数据源 ) 但这不起作用.

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.

推荐答案

经过一番搜索和试验,我未能成功尝试将报表绑定到包含子集合的自定义对象.我没有使用 .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&lt;&gt; 绑定对象到水晶报表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:用 List&lt;&gt; 绑定对象到水晶报表

基础教程推荐