C # vs Self RDLC Report learning

Source: Internet
Author: User

Recently has been busy report, rare today is free, the recent work of things summed up.

I did not know how to make this report before, never contacted. Although know can use VS Native report tool to do, but, the official gives the document is still little pitiful, many articles on the net are about the Web to make the report, rarely can find about using RDLC in WinForm to do the report. Google + Bing + Baidu, still can find about WinForm do report or very little.

When it comes to the report, you will think that the comparison with vs. is closely related to the Crystal Report. Crystal Report The things made out are very beautiful. Then it might be fastreport, which has more than 10 years of reporting experience, and a good link to vs. There are many other reporting tools that are not enumerated here. In the end, there is no Microsoft native tool good, after all, is their own things, their own things can and vs do seamless connection. Microsoft is powerful ...

I'm using the VS2010 development tool. The development language is C #. ------------------------------------See the results first .

The report is designed like this:


Look at the results:


------------------------------------steps (some of the intermediate steps can be exchanged)

1, of course, is to create a new WinForm form application.

2, in the Add a new item, find the reporting in the left template, find the report on the right, the report named Random.


After you add the report, the following figure is the interface:


In the blank of the report, click the right mouse button, in the pop-up menu, select the view-> ruler, convenient for us to design a better report size.


Note: Typically, a RDLC report is printed on a A4 paper:

Maximum report width (above tick: points after 16)


The maximum height of the report is (the tick above: to the point behind 25)


That's what I'm testing. The maximum height and maximum width should be around this value.

3, after you add the report, you can then add controls to the report. One way is in the report blank, click the right mouse button, select Insert,

You can then insert the control into it; Alternatively, the shortcut key (ctrl+alt+x) opens the toolbox, or you can drag the control directly onto the report in the Toolbox.

4, after you have added the good data, you can add the data source.

There are 2 ways I know about adding a data source.

1, in the report under the project to create a class, and in a generic way as a report data source, this method I am not quite familiar with, you can go to the official document to see, this is a link

2, create a new dataset. In this way, you can add a dataset that is not under the same project as the report. Because when you bind data to a report, you only need to ensure that the report and dataset are under the same project, the report can be designed in other projects, and the project that adds the existing item to the report is added to the data binding.

Here, I may not describe it very clearly. It doesn't matter, I know it by myself. Keep going down,

Then add the data source, here I add the data source in the second way, here, the name of the dataset is random, I still use the default bar:


5, add the format of the dataset to the dataset.


Of course, you can also click the "toolbox" in the image above.


Once you've designed the dataset, we can add data to the report. That's right. Here, when designing columns in a DataSet, the shortcut keys for adding new columns are: Ctrl+l. (not case-insensitive).

6, add the report data.

First, switch the window to the report window:


Next, find the: vs menu-> View-> report data. The shortcut to open the report data is: Ctrl+alt+d (case-insensitive). VS will pop up the report Data window:


Then, select the new-> dataset for the report Data window ...


(Here, the other two ways I don't often use, parameters I don't quite, image, is to add a local image)

In the pop-up window, do the following.


7, after the point solution is confirmed, in the Report Data window, we have just added the data source.


Next, we drag the items from the data source to the location specified on the report.


The work of the report is finished. ------------------------------------View the report and add a data source to the report.

My approach here is to dynamically add data to the report.

1, go back to the WinForm Design window, open the Toolbox, find a control named ReportViewer under the report category, add it to the WinForm form, and adjust its size.


2, double-click the WinForm form or press F7. Go to the background code and add the following code:

Add the following namespaces:

Using Microsoft.Reporting.WinForms;
and add the following code

private void Form1_Load (object sender, EventArgs e)
        {
            ///----Specify the report external data source
            datatable table = new DataTable (); C3/>table. Columns.Add ("Tools", typeof (String));
            Table. Columns.Add ("Language", typeof (String));
            Table. Rows.Add ("VS2010", "C # 4.0");

            ---Add data source
            reportdatasource rds = new ReportDataSource ();
            Rds. Name = "DataSet1";
            Rds. Value = table;
            ---Bind the data source to the report
            THIS.REPORTVIEWER1.LOCALREPORT.DATASOURCES.ADD (RDS);
            ---Specify the displayed report
            This.reportViewer1.LocalReport.ReportPath = @ "to the Report Viewer ... \.. \REPORT1.RDLC ";
            This.reportViewer1.RefreshReport ();
        }

Here, please note:
Rds.  Name = "DataSet1"; The DataSet1 here is from the name shown in the following figure.


3, run the program (Ctrl + F5) to see:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.