Reportviewer and rdlc report notes

Source: Internet
Author: User

Recently, rdlc reports have not been used before, so many small ups and downs have been encountered, so it is easy for you to review them later.

When I first started using it, I thought it was really awkward. Later I found that after some time, I found that it was actually quite good and supported many forms, but I only used tables and split tables, the following describes the basic usage of the two tables. If any, please kindly advise.

I. Introduction

The combination of reportviewer and rdlcr reports is roughly as follows:

1. Drag and Drop a reportviewer control in the form.

2.ProgramAdd an rdlc report.

3. Add Report items for the report and bind the data source.

4. Use reportviewer to load the rdlc report to add data and set the display format.

There is nothing to say about the first two. Step 1 is also relatively easy, and there are some introductions on the Internet. Step 1 is the most difficult to do (at least this step is the most frustrating part of my first contact ). So we will start with step 3.

Ii. Detailed introduction

1. Add a report item table to a report

(1) After creating a report, it should look like the following:

(2) drag a table from the left-side toolbar to the report design page. "dataset attributes" appears. If no data source exists in the current project, the "Data Source wizard" dialog box appears. As follows:

(3) Add a data source. You can select four forms in the figure. The "object" is used by the author, so the object is also selected here. The following dialog box is displayed after you click it.

Note: the "object" here can be supported by any C. Here I create a simple class.

(4) Click "complete" and return to the "dataset properties" dialog box, which will look like the following:

(5) Select "Data Source" and "dataset" and click "OK ".

(6) When pointing to a cell, an icon appears in the upper right corner of the cell. Click the icon to select the field to be bound to the selected cell. As follows:

After the fields are bound, this simple report is complete. Of course, rdlc also supports some complex settings, such as running some simple expressions for Data grouping. These are not described here.

2. Add a chart (line chart) for a report)

In the usage of line chart splitting, the data from adding a chart to selecting a dataset is the same. I will not talk about it here. I will mainly talk about binding fields. As shown in

3. Load reports for reportviewer and bind data

This block is relatively simple, and tables and charts are bound.CodeIt is the same, so you can check the Code as follows:

View code

 1           Private   Void Form1_load ( Object  Sender, eventargs E)  2   {  3              This  . Rpttesttable. refreshreport ();  4   5               ///////////////////////////  /  6               //  Declare a data set to define a report data source  7               //  There should be many types of data sets supported by reports.  8 System. Collections. arraylist listtable = New  System. Collections. arraylist (); 9               //  Add some data to the list  10 Random random = New  Random ();  11               For ( Int I = 0 ; I < 5 ; I ++ )  12   {  13                  For ( Int J = 0 ; J < 5 ; J ++ )  14   {  15 Datamodel model = New  Datamodel ();  16 Model. ID = (I + 1  ). Tostring ();  17 Model. datavalue = random. Next ( 1 , 200  ). Tostring ();  18 Model. Time = Datetime. Now. addhours (j). tow.timestring ();  19   Listtable. Add (model );  20   }  21   }  22   23               // The following is an important part: bind table data  24               //  The namespace Microsoft. Reporting. winforms.  25               //  Define the data source. The dataset name "dstest" is used here. This name must be the same as the one added in the report.  26 Reportdatasource sourcetable = New Reportdatasource ( "  Dstest  "  , Listtable );  27              This . Rpttesttable. Clear (); //  Clear the reportview  28               This . Rpttesttable. localreport. reportpath = @"  ... \ Rpttesttable. rdlc  " ; //  Set Report path  29               This . Rpttesttable. localreport. CES. Add (sourcetable );//  Add Data Source  30               This . Rpttesttable. setdisplaymode (displaymode. printlayout ); //  Set Display Mode  31               This . Rpttesttable. zoommode = zoommode. pagewidth; //  Set the report bloom Mode  32               This . Rpttesttable. refreshreport (); // Refresh report  33               //  Now you can see the result of running the program.  34   35               //  The bound chart data below is basically the same as that in the middle  36 Reportdatasource sourcecurve = New Reportdatasource ( "  Dscurve  "  , Listtable );  37               This . Rpttestcurve. Clear ();  38               This . Rpttestcurve. localreport. reportpath = @"  ... \ Rpttestcurve. rdlc  "  ;  39               This  . Rpttestcurve. localreport. CES. Add (sourcecurve );  40               This  . Rpttestcurve. setdisplaymode (displaymode. printlayout );  41              This . Rpttestcurve. zoommode = Zoommode. pagewidth;  42               This  . Rpttestcurve. refreshreport ();  43               //  Now you can see the result of running the program.  44 }

4. The result is as follows:

At this point, the entire report is complete.

Although this is done, some problems can be found in the preceding report. For example, the data ID items in the table are repeated, but such data is unfriendly in actual applications. For details about how to improve the report, refer to the following.

 

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.