动态传递参数到DevExpress.XtraReports的小结 .

本文介绍了DevExpress报表设计中三种参数传递方法:构造函数、属性设置及DataSet方式,并探讨了用户自定义报表设计时遇到的问题及解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前两种方法和WinForm一样,可以传递参数、数组、实体对象、DataTable等
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。报表界面的Field List中会自动加入刚添加进去的表和栏目,然后在拉动Field List栏中的Column到报表中,设计好後。在报表的代码中:
private void Detail_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
 {
    this.DataSource = ds.Table[0];
}

我使用以上三种方法都没问题。

但我在允许用户修改报表设计
DevExpress.XtraReports.UI.XtraReport report = DevExpress.XtraReports.UI.XtraReport.FromFile(Application.StartupPath + "//ReportTest.repx" );
report.ShowDesigner();
如果采用第1、2种方法,怎么也不行。后来只能变通,把要传递的数据保存在XML中,然后在Detail_BeforePrint事件中把XML文件中的数据读出来。

查看帮助说明如下:
in the assembly (represented by the .EXE or .DLL file) which produced the REPX file. Its path is also mentioned in the REPX file's header;

  1. in the current assembly where the FromFile method is called from;
  2. in the assemblies referenced by the current assembly.

If this class type is not found, then an instance of the XtraReport class is created.

Also, the saved state can be applied to the created report instance, if the loadState parameter is set to true.

等有空的时候使用反射试试,看能否让第1、2中传递参数的方法也可以实现用户自定义报表。

转载于:https://www.cnblogs.com/xiaofengfeng/archive/2012/02/12/2348465.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值