Devexpress Xtrareport side by side report

What is a side-by-side report?

  

According to my personal understanding: a side-by- side report is to put two or more reports on one report page.

Note: This example uses the same data source for convenience, but you can use the same method to display two completely different (using different data sources) reports in one report document.

As usual, let's take a look at the effect we finally achieved, as shown in the figure:

  

 

Step 1: Form layout.

Create a new WinForm form, pull in the third-party controls SimpleButton, DocumentViewer, SplitContainerControl, LabelControl, TextEdit, GroupControl, it is nothing more than setting the space Dock property, as well as the font Text property, etc. I will not elaborate on the simple layout. You can refer to the first article in the series.

 

Step 2 : Create two Devexpress XtraReport report files. One is the detailed report DetailSideBySideRpt (used to bind to the last displayed side-by-side report MasterSideBySideRpt), and the other is the last displayed side-by-side report MasterSideBySideRpt as shown in the figure:

   

  Then create a new MasterSideBySideRpt, as shown in the figure:

    

 

So how to display our newly created DetailSideBySideRpt report side by side to MasterSideBySideRpt?

 

Method 1: Add the control XrSubreport as shown in the figure:

  

 

You can also add code manually

this.xrSubreport1.ReportSource = new Create a side-by-side report.DetailSideBySideRpt();

this.xrSubreport2.ReportSource = new Create a side-by-side report.DetailSideBySideRpt(); //Here I use the same DetailSideBySideRpt for the two side-by-side reports, you can use different

Form code

  

 1       /// <summary>
 2         /// 获取数据集
 3         /// </summary>
 4         /// <returns>返回数据集</returns>
 5         private DataSet Getdataset()
 6         {
 7             DataSet ds = new DataSet();
 8             string cstr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString.ToString();
 9             SqlConnection mycon = new SqlConnection(cstr);
10             try
11             {
12                 mycon.Open();
13                 SqlCommand mycom = new SqlCommand("select * from jiaochainfo", mycon);
14                 SqlDataAdapter dpt = new SqlDataAdapter(mycom);
15                 dpt.Fill(ds, "jiaochainfo");
16                 mycon.Close();
17             }
18             catch (Exception ex)
19             {
20 
21                 MessageBox.Show(ex.Message);
22             }
23 
24             return ds;
25         }
26         //点击事件
27         private void simpleButton1_Click(object sender, EventArgs e)
28         {
29             DataSet ds = Getdataset();
30             XtraReport1 report = new XtraReport1(ds);
31             report.Landscape = true;
32             MianXtrareport rpt = new MianXtrareport(ds);
33             rpt.Landscape = true;
34             documentViewer1.DocumentSource =rpt;
 35              // Display the document of the main report 
36              rpt.CreateDocument();
 37          }
 38  
39      }

Detailed report code

  

1        
2          // Construct data parameter binding field 
3          public XtraReport1(DataSet ds)
 4          {
 5              InitializeComponent();
 6              this .DataSource = ds;
 7              this .DataMember = " jiaochainfo " ;
 8              this .xrLabel1.DataBindings.Add( " Text " ,ds, " name " );
 9              this .xrLabel2.DataBindings.Add( " Text " ,ds, " sex " );
 10             this.xrLabel3.DataBindings.Add("Text",ds,"older");
11         }

main report code

  

1         // Main report constructor 
2          public MianXtrareport( DataSet ds)
 3          {
 4              InitializeComponent();
 5              // The key step, the report source of the xrsubreport control is equal to xtrareport 
6              this .xrSubreport1.ReportSource = new side-by-side report.XtraReport1(ds) ;
 7              this .xrSubreport2.ReportSource = new side-by-side report.XtraReport1(ds);
 8  
9          }
 10  
11          // Use the FilterString property to filter the data source 
12  
13          private  void xrSubreport1_BeforePrint( objectsender, System.Drawing.Printing.PrintEventArgs e)
 14          {
 15              // jtype is field 16 of the database library
              ((XRSubreport)sender).ReportSource.FilterString = " jtype == 'Sports star' " ;
 17         }
 18 // Use FilterString property filter data source 19 20 private void xrSubreport2_BeforePrint( object sender, System.Drawing.Printing.PrintEventArgs e)
 21         {
 22              ((XRSubreport)sender).ReportSource.FilterString = " jtype == 'Movie star' " ;
 23          }          
 
           

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325268223&siteId=291194637