列表中的 Microsoft WinForm ReportViewer

发布于 2024-07-20 03:16:35 字数 565 浏览 3 评论 0原文

任何人都可以提供代码片段、教程链接或有关如何从对象列表在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绾颜 2024-07-27 03:16:35

对于 winform ReportViewer:包括以下代码

public class Dog
    {

        int legs;

        public int Legs
        {
            get { return legs; }
            set { legs = value; }
        }
        string name;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        string breed;

        public string Breed
        {
            get { return breed; }
            set { breed = value; }
        }

    }

    public class DogBll
    {
        List<Dog> myDog;
        public DogBll()
        {
            myDog = new List<Dog>();
            myDog.Add(new Dog() { Legs = 10, Name = "mimi", Breed = "german" });
            myDog.Add(new Dog() { Legs = 4, Name = "momo", Breed = "english" });
        }
        public List<Dog> GetDogs()
        {
            return myDog;
        }
    }

构建您的解决方案,将 ReportViewer 控件添加到您的表单,在 ReportViewer 智能标记上,创建一个新报告并选择对象数据源,展开您的类并检查 Dog 类作为您的对象数据源。 再次选择您的报表查看器控件,然后选择新创建的报表,将自动创建一个 DogBindingSource。 在表单类中,将以下代码添加到类的顶部。 您可以在公共分部类 Form1 : Form { 语句之后,但在构造函数之前使用第一行在

private DogBll _dogBll = new DogBll();

formload() 上,添加:

this.DogBindingSource.DataSource = _dogBll.GetDogs();

对于 webform reportviewer:您应该提供一个将返回 Dog 列表的函数,在此类中它应该包含默认构造函数。

namespace MyNS 
{ 
   public class Dog 
   { 
      public int Legs { get; set; } 
      public string Name { get; set; } 
      public string Breed { get; set; } 
   }
   public class DogBll
   {
      public DogBll()
      {
      }
      public List<Dog> GetDogs(List<Dog> myDog)//make sure you set the parameter in object datasource
      {
          return myDog;
      }
    }
} 

添加报告查看器向导控件,选择数据源作为您刚刚创建的新函数 GetDogs(),根据 Dog 类中的 3 个公共属性定义报告。 在表单中添加对象数据源,让报表使用该对象数据源。 最后,在对象数据源中设置GetDogs()的参数。

For winform reportviewer: include the following code

public class Dog
    {

        int legs;

        public int Legs
        {
            get { return legs; }
            set { legs = value; }
        }
        string name;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        string breed;

        public string Breed
        {
            get { return breed; }
            set { breed = value; }
        }

    }

    public class DogBll
    {
        List<Dog> myDog;
        public DogBll()
        {
            myDog = new List<Dog>();
            myDog.Add(new Dog() { Legs = 10, Name = "mimi", Breed = "german" });
            myDog.Add(new Dog() { Legs = 4, Name = "momo", Breed = "english" });
        }
        public List<Dog> GetDogs()
        {
            return myDog;
        }
    }

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

private DogBll _dogBll = new DogBll();

On formload(), add:

this.DogBindingSource.DataSource = _dogBll.GetDogs();

For webform reportviewer: You should provide a function that will return a list of Dog, in this class it should contain a default constructor.

namespace MyNS 
{ 
   public class Dog 
   { 
      public int Legs { get; set; } 
      public string Name { get; set; } 
      public string Breed { get; set; } 
   }
   public class DogBll
   {
      public DogBll()
      {
      }
      public List<Dog> GetDogs(List<Dog> myDog)//make sure you set the parameter in object datasource
      {
          return myDog;
      }
    }
} 

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.

來不及說愛妳 2024-07-27 03:16:35

对于本地报告,您可以像这样指定数据源:

var reportViewer = New ReportViewer();
var reportDataSource = New ReportDataSource("MyNS_Dog", MyDogs);
reportViewer.LocalReport.DataSources.Add(reportDataSource);

For a local report, you can specify your data source like this:

var reportViewer = New ReportViewer();
var reportDataSource = New ReportDataSource("MyNS_Dog", MyDogs);
reportViewer.LocalReport.DataSources.Add(reportDataSource);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文