1、 新建XtraForm(可增長printBarManager1打印控件)ide
2、引用類using DevExpress.XtraReports.UI;//使用報表屬性須要用到該類spa
//實例化打印報表 public Reports.XtraReport_ZD rpt = new Reports.XtraReport_ZD();
3、首先在XtraReportBase.Bands屬性中添加Bands(添加帶區)code
ReportHeaderBand header = new ReportHeaderBand();//表頭(一次) //把帶區加到報表中 rpt.Bands.AddRange(new DevExpress.XtraReports.UI.Band[] { detail, header, pagefood, topM, ghBand });
4、 在相應的Bands的XRControl.Controls屬性中添加控件(往相應的帶區添加控件)orm
//新增控件,設定控件的屬性 XRLabel xlabRH = new XRLabel(); xlabRH.Text = "表頭"; xlabRH.BackColor = Color.SeaGreen; xlabRH.Font = new Font(new System.Drawing.FontFamily("宋體"), 20, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); xlabRH.Size = new Size(200, 42);//設置控件大小 xlabRH.LocationF = new System.Drawing.Point(100, 500); //把控件添加到帶區 rpt.Bands[BandKind.ReportHeader].Controls.Add(xlabRH);
5、綁定數據blog
rpt.DataSource = FillDataset();//設置報表數據源 rpt.DataMember = ((DataSet)rpt.DataSource).Tables[0].TableName; //給相應的控件賦值..........//打開報表rpt.ShowPreviewDialog();