Printing and making reports in c# winform

后端 未结 2 1251
再見小時候
再見小時候 2021-02-05 17:50

I used in Delphi QuickReport to create reports and print. What can I use to do this in .NET C#?

I added some reporting elements (Microsoft reports and Crystal reports) t

相关标签:
2条回答
  • 2021-02-05 18:07

    You can use the built in reports to generate nice reports wihtout requiring a database.

    Create a class for your data, in my case, I am going to create a person class:

    class Person
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string AddressLine1 { get; set; }
        public string AddressLine2 { get; set; }
    }
    
    • Next I am going to add a report using the report wizard (Add New Item -> Reporting -> Report Wizard).

    • For the datasource, I am going to select Object and then point it to my Person class. Datasource from a class

    • Select the columns you want for your details, I am just dragging all of them into the values for simplicity.

    Report Wizard Fields

    • Walk through the rest of the wizard just selecting the defaults and you should then see your report.

    • Now you can add a ReportViewer control to a form and set the report to the report you just created. This should create a PersonBindingSource on your form as well.

    • Set the PersonBindingSource's data to a list in memory:

      BindingList<Person> myPeople = new BindingList<Person>();
      myPeople.Add(new Person() { FirstName = "John" , LastName = "Doe"});
      myPeople.Add(new Person() { FirstName = "Jane" , LastName = "Doe"});
      myPeople.Add(new Person() { FirstName = "Jerry" , LastName = "Smithers" });
      
      PersonBindingSource.DataSource = myPeople;
      reportViewer1.RefreshReport();
      this.reportViewer1.RefreshReport();
      

    With the final report looking like this:

    Final Report

    0 讨论(0)
  • 2021-02-05 18:15

    Crystal Reports will work perfectly for you. Actually you can generate reports without a database. Check out this project and it should get you started and is just like what you are trying to do.

    You this helps you!

    0 讨论(0)
提交回复
热议问题