关于DevExpress的XtraReports的用法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关于DevExpress的XtraReports的用法相关的知识,希望对你有一定的参考价值。

在XtraReports里面的设计模版中可以新建一个DetailReport,在里面又有Detail1,现在的问题是如何能动态的将数据绑定到这个Detail1里面。。。如果你用过这个控件 麻烦告诉我 如果你能将我的问题解决 我会额外增加悬赏。。。。我用的是C#winform开发的。。。

XtraReport report = new XtraReport();// 建立报表实例
report.Dpi = 254F;
report.DataSource = dt;//设置报表数据源

report.ReportUnit = DevExpress.XtraReports.UI.ReportUnit.TenthsOfAMillimeter;
//report.PageHeight = 1169;
//report.PageWidth = 827;
if (radioGroup2.EditValue.ToString() == "A4")
report.PaperKind = System.Drawing.Printing.PaperKind.A4;
if (radioGroup2.EditValue.ToString() == "A5")
report.PaperKind = System.Drawing.Printing.PaperKind.A5;

report.Margins = new System.Drawing.Printing.Margins(107, 99, 99, 107);
//报表头
ReportHeaderBand reportHeader = new ReportHeaderBand();
reportHeader.Dpi = 254F;
//数据
DetailBand detail = new DetailBand();
detail.Dpi = 254F;
//页眉
PageHeaderBand pageHeader = new PageHeaderBand();
pageHeader.Dpi = 254F;

//页脚
PageFooterBand pageFooter = new PageFooterBand();
pageFooter.Dpi = 254F;

//分组头
GroupHeaderBand groupHeader = new GroupHeaderBand();
groupHeader.Dpi = 254F;

groupHeader.GroupFields.AddRange(new DevExpress.XtraReports.UI.GroupField[] new DevExpress.XtraReports.UI.GroupField("箱号", DevExpress.XtraReports.UI.XRColumnSortOrder.Ascending));
//分组尾
GroupFooterBand groupFooter = new GroupFooterBand();
groupFooter.Dpi = 254F;

//报表尾
ReportFooterBand reportFooter = new ReportFooterBand();
reportFooter.Dpi = 254F;

pageHeader.Height = Convert.ToInt32(spinEdit1.Value); ;
detail.Height = Convert.ToInt32(spinEdit2.Value);
pageFooter.Height = 50;
groupHeader.Height = 0;
groupFooter.Height = 50;
reportFooter.Height = 50;

report.Bands.AddRange(new DevExpress.XtraReports.UI.Band[] reportHeader, detail, pageHeader, reportFooter, pageFooter, groupHeader, groupFooter );
//封面 DevExpress.XtraReports.UI.XRLabel A1 = new DevExpress.XtraReports.UI.XRLabel();
A1.Dpi = 254F;
A1.Font = new System.Drawing.Font("宋体", 36F, System.Drawing.FontStyle.Bold);
A1.Location = new System.Drawing.Point(0, 212);
A1.Name = "A1";
A1.Padding = new DevExpress.XtraPrinting.PaddingInfo(5, 5, 0, 0, 254F);
A1.ParentStyleUsing.UseFont = false;
A1.Size = new System.Drawing.Size(report.PageWidth - (report.Margins.Left + report.Margins.Right) - 2, 190);
A1.Text = "浙江XXX服饰股份有限公司";
A1.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;

report.Bands[BandKind.ReportHeader].Controls.Add(A1);
DevExpress.XtraReports.UI.XRLabel A2 = new DevExpress.XtraReports.UI.XRLabel();
A2.Dpi = 254F;
A2.Font = new System.Drawing.Font("宋体", 36F, System.Drawing.FontStyle.Bold);
A2.Location = new System.Drawing.Point(0, 466);
A2.Name = "A2";
A2.Padding = new DevExpress.XtraPrinting.PaddingInfo(5, 5, 0, 0, 254F);
A2.ParentStyleUsing.UseFont = false;
A2.Size = new System.Drawing.Size(report.PageWidth - (report.Margins.Left + report.Margins.Right) - 2, 148);
A2.Text = "装 箱 单";
A2.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;

report.Bands[BandKind.ReportHeader].Controls.Add(A2);
DevExpress.XtraReports.UI.XRLabel A3 = new DevExpress.XtraReports.UI.XRLabel();
A3.Dpi = 254F;
A3.Font = new System.Drawing.Font("宋体", 28F, System.Drawing.FontStyle.Bold);
A3.Location = new System.Drawing.Point(0, 762);
A3.Name = "A3";
A3.Padding = new DevExpress.XtraPrinting.PaddingInfo(5, 5, 0, 0, 254F);
A3.ParentStyleUsing.UseFont = false;
A3.Size = new System.Drawing.Size(report.PageWidth - (report.Margins.Left + report.Margins.Right) - 2, 127);
A3.Text = "订单号:" + str_HTBN;
A3.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;

report.Bands[BandKind.ReportHeader].Controls.Add(A3);
DevExpress.XtraReports.UI.XRLabel A4 = new DevExpress.XtraReports.UI.XRLabel();
A4.Dpi = 254F;
A4.Font = new System.Drawing.Font("宋体", 28F, System.Drawing.FontStyle.Bold);
A4.Location = new System.Drawing.Point(0, 910);
A4.Name = "A4";
A4.Padding = new DevExpress.XtraPrinting.PaddingInfo(5, 5, 0, 0, 254F);
A4.ParentStyleUsing.UseFont = false;
A4.Size = new System.Drawing.Size(report.PageWidth - (report.Margins.Left + report.Margins.Right) - 2, 127);
A4.Text = "客户名:" + str_KHName;
A4.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;

report.Bands[BandKind.ReportHeader].Controls.Add(A4);
DevExpress.XtraReports.UI.XRLabel A5 = new DevExpress.XtraReports.UI.XRLabel();
A5.Dpi = 254F;
A5.Font = new System.Drawing.Font("宋体", 22F, System.Drawing.FontStyle.Bold);
A5.Location = new System.Drawing.Point(0, 1058);
A5.Name = "A5";
A5.Padding = new DevExpress.XtraPrinting.PaddingInfo(5, 5, 0, 0, 254F);
A5.ParentStyleUsing.UseFont = false;
A5.Size = new System.Drawing.Size(report.PageWidth - (report.Margins.Left + report.Margins.Right) - 2, 127);
A5.Text = "共 " + hejixiangshu + " 箱( 方案编号: " + str_Fenzu + " )";
A5.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;

report.Bands[BandKind.ReportHeader].Controls.Add(A5);
DevExpress.XtraReports.UI.XRLabel A6 = new DevExpress.XtraReports.UI.XRLabel();
A6.Dpi = 254F;
A6.Font = new System.Drawing.Font("宋体", 22F, System.Drawing.FontStyle.Bold);
A6.Location = new System.Drawing.Point(212, 1206);
A6.Name = "A5";
A6.Padding = new DevExpress.XtraPrinting.PaddingInfo(5, 5, 0, 0, 254F);
A6.ParentStyleUsing.UseFont = false;
A6.Size = new System.Drawing.Size(317, 106);
A6.Text = "其中:";
A6.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleRight;

report.Bands[BandKind.ReportHeader].Controls.Add(A6);
DevExpress.XtraReports.UI.XRLabel A7 = new DevExpress.XtraReports.UI.XRLabel();
A7.Dpi = 254F;
A7.Font = new System.Drawing.Font("宋体", 22F, System.Drawing.FontStyle.Bold);
A7.Location = new System.Drawing.Point(0, 2286);
A7.Name = "A5";
A7.Padding = new DevExpress.XtraPrinting.PaddingInfo(5, 5, 0, 0, 254F);
A7.ParentStyleUsing.UseFont = false;
A7.Size = new System.Drawing.Size(report.PageWidth - (report.Margins.Left + report.Margins.Right) - 2, 148);
A7.Text = DateTime.Now.ToString("yyyy 年 MM 月 dd 日");
A7.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;

report.Bands[BandKind.ReportHeader].Controls.Add(A7);
DevExpress.XtraReports.UI.XRPageBreak A8 = new DevExpress.XtraReports.UI.XRPageBreak();
A8.Dpi = 254F; A8.Location = new System.Drawing.Point(0, 2455);
report.Bands[BandKind.ReportHeader].Controls.Add(A8);
//封面合计
int lie = -1;
int a = 529;//X
int b = 1206;//Y
int c = 508;//size x
int d = 106;//size y
for (int i = 5; i < dt.Columns.Count; i++)

if (dt.Columns[i].Caption != "长袖衬衫规格" && dt.Columns[i].Caption != "中袖衬衫规格" && dt.Columns[i].Caption != "短袖衬衫规格")

lie++;

DevExpress.XtraReports.UI.XRLabel A = new DevExpress.XtraReports.UI.XRLabel();
A.Dpi = 254F;
A.Font = new System.Drawing.Font("宋体", 22F, System.Drawing.FontStyle.Bold);
A.Location = new System.Drawing.Point(a, b + lie * d);
A.Name = "A" + i + "标";
A.Padding = new DevExpress.XtraPrinting.PaddingInfo(5, 5, 0, 0, 254F);
A.ParentStyleUsing.UseFont = false;
A.Size = new System.Drawing.Size(c, d);
A.Text = dt.Columns[i].Caption + ":";
A.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleRight;

report.Bands[BandKind.ReportHeader].Controls.Add(A);
DevExpress.XtraReports.UI.XRLabel B = new DevExpress.XtraReports.UI.XRLabel();
B.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] new DevExpress.XtraReports.UI.XRBinding("Text", dt, dt.Columns[i].Caption, "") );
B.Dpi = 254F;
B.Font = new System.Drawing.Font("宋体", 22F, System.Drawing.FontStyle.Bold);
B.Location = new System.Drawing.Point(a + c, b + lie * d);
B.Name = "A" + i;
B.Padding = new DevExpress.XtraPrinting.PaddingInfo(5, 5, 0, 0, 254F);
B.ParentStyleUsing.UseFont = false;
B.Size = new System.Drawing.Size(c, d);
DevExpress.XtraReports.UI.XRSummary C = new DevExpress.XtraReports.UI.XRSummary();
C.FormatString = "0 件";
C.Running = DevExpress.XtraReports.UI.SummaryRunning.Report;
B.Summary = C;
B.Text = dt.Columns[i].Caption;
B.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;

report.Bands[BandKind.ReportHeader].Controls.Add(B);



int colCount = dt.Columns.Count;
//int[] cw = 100, 100, 180, 100, 400 ;
string p = spinEdit3.Value + "," + spinEdit4.Value + "," + spinEdit5.Value + ",100," + spinEdit6.Value;
string[] cw = p.Split(\',\');
int cw8 = 172;
int cw5 = Convert.ToInt32(cw[0]) + Convert.ToInt32(cw[1]) + Convert.ToInt32(cw[2]) + Convert.ToInt32(cw[3]) + Convert.ToInt32(cw[4]);
int colWidth = (report.PageWidth - (report.Margins.Left + report.Margins.Right) - cw5) / (colCount - chenshancount - 5);
if (colWidth < cw8)
colWidth = (report.PageWidth - (report.Margins.Left + report.Margins.Right) - cw5 - chenshancount * cw8) / (colCount - 2 * chenshancount - 5);
else
cw8 = colWidth;
参考技术A 这是我纯代码写的一段装箱单的报表代码,分享一下

XtraReport report = new XtraReport();// 建立报表实例
report.Dpi = 254F;
report.DataSource = dt;//设置报表数据源

report.ReportUnit = DevExpress.XtraReports.UI.ReportUnit.TenthsOfAMillimeter;
//report.PageHeight = 1169;
//report.PageWidth = 827;
if (radioGroup2.EditValue.ToString() == "A4")
report.PaperKind = System.Drawing.Printing.PaperKind.A4;
if (radioGroup2.EditValue.ToString() == "A5")
report.PaperKind = System.Drawing.Printing.PaperKind.A5;

report.Margins = new System.Drawing.Printing.Margins(107, 99, 99, 107);
//报表头
ReportHeaderBand reportHeader = new ReportHeaderBand();
reportHeader.Dpi = 254F;
//数据
DetailBand detail = new DetailBand();
detail.Dpi = 254F;
//页眉
PageHeaderBand pageHeader = new PageHeaderBand();
pageHeader.Dpi = 254F;

//页脚
PageFooterBand pageFooter = new PageFooterBand();
pageFooter.Dpi = 254F;

//分组头
GroupHeaderBand groupHeader = new GroupHeaderBand();
groupHeader.Dpi = 254F;

groupHeader.GroupFields.AddRange(new DevExpress.XtraReports.UI.GroupField[] new DevExpress.XtraReports.UI.GroupField("箱号", DevExpress.XtraReports.UI.XRColumnSortOrder.Ascending));
//分组尾
GroupFooterBand groupFooter = new GroupFooterBand();
groupFooter.Dpi = 254F;

//报表尾
ReportFooterBand reportFooter = new ReportFooterBand();
reportFooter.Dpi = 254F;

pageHeader.Height = Convert.ToInt32(spinEdit1.Value); ;
detail.Height = Convert.ToInt32(spinEdit2.Value);
pageFooter.Height = 50;
groupHeader.Height = 0;
groupFooter.Height = 50;
reportFooter.Height = 50;

report.Bands.AddRange(new DevExpress.XtraReports.UI.Band[] reportHeader, detail, pageHeader, reportFooter, pageFooter, groupHeader, groupFooter );
//封面 DevExpress.XtraReports.UI.XRLabel A1 = new DevExpress.XtraReports.UI.XRLabel();
A1.Dpi = 254F;
A1.Font = new System.Drawing.Font("宋体", 36F, System.Drawing.FontStyle.Bold);
A1.Location = new System.Drawing.Point(0, 212);
A1.Name = "A1";
A1.Padding = new DevExpress.XtraPrinting.PaddingInfo(5, 5, 0, 0, 254F);
A1.ParentStyleUsing.UseFont = false;
A1.Size = new System.Drawing.Size(report.PageWidth - (report.Margins.Left + report.Margins.Right) - 2, 190);
A1.Text = "浙江XXX服饰股份有限公司";
A1.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;

report.Bands[BandKind.ReportHeader].Controls.Add(A1);
DevExpress.XtraReports.UI.XRLabel A2 = new DevExpress.XtraReports.UI.XRLabel();
A2.Dpi = 254F;
A2.Font = new System.Drawing.Font("宋体", 36F, System.Drawing.FontStyle.Bold);
A2.Location = new System.Drawing.Point(0, 466);
A2.Name = "A2";
A2.Padding = new DevExpress.XtraPrinting.PaddingInfo(5, 5, 0, 0, 254F);
A2.ParentStyleUsing.UseFont = false;
A2.Size = new System.Drawing.Size(report.PageWidth - (report.Margins.Left + report.Margins.Right) - 2, 148);
A2.Text = "装 箱 单";
A2.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;

report.Bands[BandKind.ReportHeader].Controls.Add(A2);
DevExpress.XtraReports.UI.XRLabel A3 = new DevExpress.XtraReports.UI.XRLabel();
A3.Dpi = 254F;
A3.Font = new System.Drawing.Font("宋体", 28F, System.Drawing.FontStyle.Bold);
A3.Location = new System.Drawing.Point(0, 762);
A3.Name = "A3";
A3.Padding = new DevExpress.XtraPrinting.PaddingInfo(5, 5, 0, 0, 254F);
A3.ParentStyleUsing.UseFont = false;
A3.Size = new System.Drawing.Size(report.PageWidth - (report.Margins.Left + report.Margins.Right) - 2, 127);
A3.Text = "订单号:" + str_HTBN;
A3.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;

report.Bands[BandKind.ReportHeader].Controls.Add(A3);
DevExpress.XtraReports.UI.XRLabel A4 = new DevExpress.XtraReports.UI.XRLabel();
A4.Dpi = 254F;
A4.Font = new System.Drawing.Font("宋体", 28F, System.Drawing.FontStyle.Bold);
A4.Location = new System.Drawing.Point(0, 910);
A4.Name = "A4";
A4.Padding = new DevExpress.XtraPrinting.PaddingInfo(5, 5, 0, 0, 254F);
A4.ParentStyleUsing.UseFont = false;
A4.Size = new System.Drawing.Size(report.PageWidth - (report.Margins.Left + report.Margins.Right) - 2, 127);
A4.Text = "客户名:" + str_KHName;
A4.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;

report.Bands[BandKind.ReportHeader].Controls.Add(A4);
DevExpress.XtraReports.UI.XRLabel A5 = new DevExpress.XtraReports.UI.XRLabel();
A5.Dpi = 254F;
A5.Font = new System.Drawing.Font("宋体", 22F, System.Drawing.FontStyle.Bold);
A5.Location = new System.Drawing.Point(0, 1058);
A5.Name = "A5";
A5.Padding = new DevExpress.XtraPrinting.PaddingInfo(5, 5, 0, 0, 254F);
A5.ParentStyleUsing.UseFont = false;
A5.Size = new System.Drawing.Size(report.PageWidth - (report.Margins.Left + report.Margins.Right) - 2, 127);
A5.Text = "共 " + hejixiangshu + " 箱( 方案编号: " + str_Fenzu + " )";
A5.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;

report.Bands[BandKind.ReportHeader].Controls.Add(A5);
DevExpress.XtraReports.UI.XRLabel A6 = new DevExpress.XtraReports.UI.XRLabel();
A6.Dpi = 254F;
A6.Font = new System.Drawing.Font("宋体", 22F, System.Drawing.FontStyle.Bold);
A6.Location = new System.Drawing.Point(212, 1206);
A6.Name = "A5";
A6.Padding = new DevExpress.XtraPrinting.PaddingInfo(5, 5, 0, 0, 254F);
A6.ParentStyleUsing.UseFont = false;
A6.Size = new System.Drawing.Size(317, 106);
A6.Text = "其中:";
A6.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleRight;

report.Bands[BandKind.ReportHeader].Controls.Add(A6);
DevExpress.XtraReports.UI.XRLabel A7 = new DevExpress.XtraReports.UI.XRLabel();
A7.Dpi = 254F;
A7.Font = new System.Drawing.Font("宋体", 22F, System.Drawing.FontStyle.Bold);
A7.Location = new System.Drawing.Point(0, 2286);
A7.Name = "A5";
A7.Padding = new DevExpress.XtraPrinting.PaddingInfo(5, 5, 0, 0, 254F);
A7.ParentStyleUsing.UseFont = false;
A7.Size = new System.Drawing.Size(report.PageWidth - (report.Margins.Left + report.Margins.Right) - 2, 148);
A7.Text = DateTime.Now.ToString("yyyy 年 MM 月 dd 日");
A7.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;

report.Bands[BandKind.ReportHeader].Controls.Add(A7);
DevExpress.XtraReports.UI.XRPageBreak A8 = new DevExpress.XtraReports.UI.XRPageBreak();
A8.Dpi = 254F; A8.Location = new System.Drawing.Point(0, 2455);
report.Bands[BandKind.ReportHeader].Controls.Add(A8);
//封面合计
int lie = -1;
int a = 529;//X
int b = 1206;//Y
int c = 508;//size x
int d = 106;//size y
for (int i = 5; i < dt.Columns.Count; i++)

if (dt.Columns[i].Caption != "长袖衬衫规格" && dt.Columns[i].Caption != "中袖衬衫规格" && dt.Columns[i].Caption != "短袖衬衫规格")

lie++;

DevExpress.XtraReports.UI.XRLabel A = new DevExpress.XtraReports.UI.XRLabel();
A.Dpi = 254F;
A.Font = new System.Drawing.Font("宋体", 22F, System.Drawing.FontStyle.Bold);
A.Location = new System.Drawing.Point(a, b + lie * d);
A.Name = "A" + i + "标";
A.Padding = new DevExpress.XtraPrinting.PaddingInfo(5, 5, 0, 0, 254F);
A.ParentStyleUsing.UseFont = false;
A.Size = new System.Drawing.Size(c, d);
A.Text = dt.Columns[i].Caption + ":";
A.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleRight;

report.Bands[BandKind.ReportHeader].Controls.Add(A);
DevExpress.XtraReports.UI.XRLabel B = new DevExpress.XtraReports.UI.XRLabel();
B.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] new DevExpress.XtraReports.UI.XRBinding("Text", dt, dt.Columns[i].Caption, "") );
B.Dpi = 254F;
B.Font = new System.Drawing.Font("宋体", 22F, System.Drawing.FontStyle.Bold);
B.Location = new System.Drawing.Point(a + c, b + lie * d);
B.Name = "A" + i;
B.Padding = new DevExpress.XtraPrinting.PaddingInfo(5, 5, 0, 0, 254F);
B.ParentStyleUsing.UseFont = false;
B.Size = new System.Drawing.Size(c, d);
DevExpress.XtraReports.UI.XRSummary C = new DevExpress.XtraReports.UI.XRSummary();
C.FormatString = "0 件";
C.Running = DevExpress.XtraReports.UI.SummaryRunning.Report;
B.Summary = C;
B.Text = dt.Columns[i].Caption;
B.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;

report.Bands[BandKind.ReportHeader].Controls.Add(B);



int colCount = dt.Columns.Count;
//int[] cw = 100, 100, 180, 100, 400 ;
string p = spinEdit3.Value + "," + spinEdit4.Value + "," + spinEdit5.Value + ",100," + spinEdit6.Value;
string[] cw = p.Split(',');
int cw8 = 172;
int cw5 = Convert.ToInt32(cw[0]) + Convert.ToInt32(cw[1]) + Convert.ToInt32(cw[2]) + Convert.ToInt32(cw[3]) + Convert.ToInt32(cw[4]);
int colWidth = (report.PageWidth - (report.Margins.Left + report.Margins.Right) - cw5) / (colCount - chenshancount - 5);
if (colWidth < cw8)
colWidth = (report.PageWidth - (report.Margins.Left + report.Margins.Right) - cw5 - chenshancount * cw8) / (colCount - 2 * chenshancount - 5);
else
cw8 = colWidth;

没贴完,找不到在哪里续贴
参考技术B 我用过这个控件,但是没用过Detail1,当初绑定某些数据是自己在文件的脚本里面写的,传进去一个dataset,然后自己循环赋值,给你看个示例吧:
//VStudy表
m_VStudy = ((System.Data.DataSet)(devReport1.DataSource)).Tables["VStudy"];
参考技术C 我用过这个控件,但是没用过Detail1,当初绑定某些数据是自己在文件的脚本里面写的,传进去一个dataset,然后自己循环赋值,给你看个示例吧:
//VStudy表
m_VStudy = ((System.Data.DataSet)(devReport1.DataSource)).Tables["VStudy"];本回答被提问者采纳

如何动态传递参数到DevExpress XtraReports

    1、xtraReport有两种类型的参数Parameter和datasource。关于parameter与datasource的区别

      1.1、如果您一个report之需要一份参数,那么可以直接使用Parameter,如果您想要传递一个List<object>那么只能使用数据源的方式传参

      1.2、如果使用Parameter的方式,report.Parameters[0].value = "xxx"就可以了,下面我们重点讨论使用数据源的方式

    2、怎样使用数据源传递List<object>

      xtraReports参数支持IList接口的类型的参数,但是官方给出了答复List<dynamic>类型暂时不支持,所以List<Type>中的Type必须是存在的类型,您如果可以定义所有reports的参数的Type,就可以通过动态修改Type的类型实现动态参数了。

      xtraReport参数支持数据链接,以及数据链接的查询结果DataSet。但是官方给出了答复。在序列化的时候,你所定义的数据链接类或者是DataSet,不会一起持久化。所以给xtraReport定义DataSet类型的参数的话,需要您自己额外写代码来保存每个xtraReport的参数

      而且DataSet的参数的访问方式为 TableName.PropertyName.这种类型的参数是没有办法随xtraReports一起保存的。使用DataSet可以实现,但是数据源参数无法保存。

    3、如何动态传递数据源类型参数给XtraReports

      如果你是devexpress19版,那么dev直接支持json类型的参数,免谈

      如果您是16版左右的,这里可以使用C#动态创建类来实现。List<Type>中的Type必须是存在的类型是么?那我就发现这个报表参数类型不存在就动态创建。

      怎么创建?参考:DynamicClass

        如果该xtraReport对应的参数再内存种不存在

        Type @class = ClassFactory.Instance.Create(properties);

        TypeDic[type] = @class;缓存类型信息

        直接使用List<dynamic> datasource作为数据源

        List里面存放var instance = (dynamic)Activator.CreateInstance(@class);

        亲测可用

参考技术A 1. 采用构造函数 具体用法: 在Report中 public partial class XtraReport1 : DevExpress.XtraReports.UI.XtraReport private int test1; public Form1(int test1) this.test1 = test1; InitializeComponent(); 调用Report int test1 = 1; XtraReport1 report = new XtraReport1(test1); report.Show(); 2.采用属性 具体用法: 在Report中 public partial class XtraReport1 : DevExpress.XtraReports.UI.XtraReport public Form1() InitializeComponent(); private int test1; public int Test1 set test1 = value; get return test1; 调用Report XtraReport1 report = new XtraReport1(); report .Test1 = 1; report.Show(); 3.采用DataSet传递参数 在报表设计界面中,从工具栏数据中拉入DataSet到界面中,选择非类型化数据集,然后给拉入的DataSet添加Table和Column。本回答被提问者采纳

以上是关于关于DevExpress的XtraReports的用法的主要内容,如果未能解决你的问题,请参考以下文章

Devexpress XtraReports的使用

devexpress extrareport 汇总函数 自定义怎么用

关于DevExpress VCL汉化方法

转关于DevExpress的gridControl的简单使用

关于解决DevExpress用DevExpress patch工具破解后经常弹出试用框的问题

转关于DevExpress的XtraTreeList使用方法总结