使用自定义类对象列表作为水晶报表的数据源
我正在尝试找到使用我自己的自定义类设计报告的方法。
我找到了链接:
1.) 如何在 Crystal 中工作带有对象数据源的报告?
2.) 在 Crystal Report 2008 中使用 .net 对象作为数据源
3.) 绑定对象列表>>水晶报表
它们非常有帮助,但是在设计报表时我一直停留在第一步,因为我的自定义类的属性未在水晶报表设计视图的字段列表中列出。
我的自定义类的示例:
class UserType
public property UIN as integer...
public property Title as string...
end class
class User
public property UIN as Integer...
public property Name as string...
public property Password as String...
public property Type as UserType...
end class
当我将类对象添加到水晶报表时,我没有从字段列表中的用户类中获取用户类型字段。
那么如何将用户类型字段添加到我的字段列表中呢?或者我必须采取另一种方法?
编辑:
我想按原样使用它的原因:
1.) 显示用户可以输入关键字的表单
2.) 程序使用 LINQ 根据关键字过滤记录
3.)当用户单击打印按钮时,我想将过滤后的记录设置为报告的数据源
I am trying to find way to design a report using my own custom class.
I found links:
1.) How to work in Crystal Report with Object Data Source?
2.) Use .net object as data source in Crystal Report 2008
3.) Binding object with List<> to Crystal Report
4.) How to assign Custom class as datasource in crystal report
They were quite helpful, but I have been stuck in the first step while designing report as my custom class's property is not listed in field list of crystal report design view.
Sample of my Custom Class:
class UserType
public property UIN as integer...
public property Title as string...
end class
class User
public property UIN as Integer...
public property Name as string...
public property Password as String...
public property Type as UserType...
end class
When I add my class objects to crystal report I do not get the usertype field from users class in field list.
So how can I add usertype field to my field list? Or do I have to take another approach?
Edit:
The reason i wanted to use it as i am:
1.) Showing a form where user can type keyword
2.) program filters the records as per keyword using LINQ
3.) when user clicks the print button, I want to set the filtered records as datasource of my report
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通常将数据集添加到您的报告中。
当您的对象类加载了数据,和/或使用用户输入的值进行过滤时(使用 linq 等进行过滤......)
这样做:
the dataset to your report normally.
When you have your object class loaded with data, and/or filtered with values entered by users (filtered with linq etc..)
do this:
您可以尝试将对象序列化为 XML,提供 XSD,然后使用 Crystal Report 的 XML 驱动程序连接到它。该报告将把该对象“视为”两张表:一张用于用户,一张用于用户类型。您将在报告中包含两个“表”,并使用internal_id 字段链接这些表。
You could try serializing the object to XML, supply an XSD, then use Crystal Report's XML driver to connect to it. The report will 'see' the object as two tables: one for the User and one for UserType. You'll include both 'tables' in the report and link the tables using the internal_id field.
为什么不为您的报表分配一个强类型数据集,这样可以省去很多麻烦呢?
Why don't you assign a strongly typed dataset to your report and save yourself lots of trouble?