zoukankan      html  css  js  c++  java
  • 动态传递参数到DevExpress.XtraReports的小结

    前两种方法和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中传递参数的方法也可以实现用户自定义报表。

  • 相关阅读:
    大数据面试题题库
    IDEA下通过Git实现代码管理
    使用QJM实现HDFS的HA配置
    1、HDFS分布式文件系统
    分析system_call中断处理过程
    由一段代码解析系统调用的原理
    从linux内核代码分析操作系统启动过程
    一个简单的时间片轮转多道程序内核
    从一段代码的汇编看计算机的工作原理
    九度OJ1468
  • 原文地址:https://www.cnblogs.com/godwar/p/1044529.html
Copyright © 2011-2022 走看看