Devexpress Xtrareport create master-detail report

 

 

first step

  Resume a winform form, pull in the controls SimpleButton, DocumentViewer, SplitContainerControl, LabelControl, TextEdit, GroupControl, simple layout (see renderings) from the toolbox, I will not elaborate.

second step

  Create a Devexpress Xtrareport report file as shown in the figure:

Create a ReportHreder in the report, as shown in the figure

Right-click in the blank area of ​​the report file, and then add a detailReport from the report, as shown in the figure

Then pull in an XRLabel in the ReportHeader to modify the Text property of the master-slave report, and then pull in the XRTable in the Detail and DetailReport areas respectively

The report layout is now complete.

third step

  create a data source,

 1   //获取数据集
 2         private DataSet Getdata()
 3         {
 4             DataSet ds = new DataSet();
 5             SqlDataAdapter dt;
 6             string constr = "server=192.168.100.222;user=sa;pwd=p@ssw1rd;database=ArchivesMenagement";
 7             SqlConnection mycon = new SqlConnection(constr);
 8             try
 9             {
10                 mycon.Open();
11                 //表一
12                 SqlCommand mycom = new SqlCommand("select * from ArchivesInfo", mycon);
13                 dt = new SqlDataAdapter(mycom);
14                 dt.Fill(ds, "ArchivesInfo");
15                 //表2
16                 SqlCommand two = new SqlCommand("select * from Department", mycon);
17                 dt = new SqlDataAdapter(two);
18                 dt.Fill(ds, "Department");
19                 mycon.Close();
 20                  // Create a primary and foreign key relationship for the dataset 
21                  DataColumn parent = ds.Tables[ " ArchivesMenagement " ].Columns[ " DeId " ];
 22                  DataColumn child = ds.Tables[ " Department " ]. Columns[ " DeId " ];
 23                  // Dataset write relation 
24                  DataRelation Rel = new DataRelation( " RelationColumn " , parent, child);
 25                  ds.Relations.Add(Rel);
 26             }
27             catch (Exception ex)
28             {
29 
30                 MessageBox.Show(ex.Message);
31             }
32           
33                 return ds;
34 
35         }
36         //实例化report
37         private void simpleButton1_Click(object sender, EventArgs e)
38         {
39             XtraReport1 report = new XtraReport1(Getdata());
40             report.Landscape = true;
41             documentViewer1.DocumentSource = report;
42             report.CreateDocument();
43            
44 
45         }
1    // Report Designer overload 
2          public XtraReport1( DataSet ds)
 3          {
 4              InitializeComponent();
 5              // Bind the main table 
6              this .DataSource = ds;
 7              this .DataMember = " ArchivesInfo " ;
 8              this .xrTableCell1.DataBindings .Add( " Text " ,ds, " DeId " );
 9              // Bind from table 
10              this .DataSource = ds;
 11              this.xrTableCell2.DataBindings.Add("Text",ds,"RelationColumn.DeId");
12             this.xrTableCell3.DataBindings.Add("Text", ds, "RelationColumn.DeName");
13 
14         }

 

Guess you like

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