列表中的 Microsoft WinForm ReportViewer
任何人都可以提供代码片段、教程链接或有关如何从对象列表在 Microsoft Report 中创建报告的信息吗?
我有以下 Dog 类:
namespace MyNS
{
public class Dog
{
public int Legs { get; set; }
public string Name { get; set; }
public string Breed { get; set; }
}
}
然后,在窗口窗体中,我有一个 ReportViewer 对象,我想从 MyNS.Dog 对象的 List 中填充该对象,如下所示:
List<MyNS.Dog> MyDogs = new List<MyNS.Dog>();
// populate array here
// and use it as datasource for ReportViewer
Any想法?
谢谢!
Can anyone provide a Code Snippet, Tutorial link or information on how to create a report in Microsoft Report from a List of objects?
I have the following Dog class:
namespace MyNS
{
public class Dog
{
public int Legs { get; set; }
public string Name { get; set; }
public string Breed { get; set; }
}
}
Then, in Window Forms, I have a ReportViewer objetct which I would like to populate from a List of MyNS.Dog objects like this:
List<MyNS.Dog> MyDogs = new List<MyNS.Dog>();
// populate array here
// and use it as datasource for ReportViewer
Any ideas?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于 winform ReportViewer:包括以下代码
构建您的解决方案,将 ReportViewer 控件添加到您的表单,在 ReportViewer 智能标记上,创建一个新报告并选择对象数据源,展开您的类并检查 Dog 类作为您的对象数据源。 再次选择您的报表查看器控件,然后选择新创建的报表,将自动创建一个 DogBindingSource。 在表单类中,将以下代码添加到类的顶部。 您可以在公共分部类 Form1 : Form { 语句之后,但在构造函数之前使用第一行在
formload() 上,添加:
对于 webform reportviewer:您应该提供一个将返回 Dog 列表的函数,在此类中它应该包含默认构造函数。
添加报告查看器向导控件,选择数据源作为您刚刚创建的新函数 GetDogs(),根据 Dog 类中的 3 个公共属性定义报告。 在表单中添加对象数据源,让报表使用该对象数据源。 最后,在对象数据源中设置GetDogs()的参数。
For winform reportviewer: include the following code
build your solution, Add a reportviewer control to your form, on the reportviewer smarttag, create a new report and choose object datasource, expand your class and check the Dog class as your object datasource. select your reportviewer control again, and choose the newly created report, a DogBindingSource is automatically created. In your form class, add the following code to the top of the class. You can use the first line after the public partial class Form1 : Form { statement, but before the constructor
On formload(), add:
For webform reportviewer: You should provide a function that will return a list of Dog, in this class it should contain a default constructor.
add a report viewer wizard control, select the datasource as the new function you just created, GetDogs(), define your report based on the 3 public properties in your Dog class. Add an object datasource in your form, point the report to use the object datasource. Finally, set the parameter of GetDogs() in the object datasource.
对于本地报告,您可以像这样指定数据源:
For a local report, you can specify your data source like this: