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

  • 相关阅读:
    Codeforces Round #417 C. Sagheer and Nubian Market
    linux 终端抓包命令
    计算机网络体系结构分析
    排序算法-快速排序
    排序算法-堆排序
    排序算法-希尔排序
    排序算法-插入排序
    排序算法-冒泡排序
    排序算法-选择排序
    杂谈:终端小工具
  • 原文地址:https://www.cnblogs.com/godwar/p/1044529.html
Copyright © 2011-2022 走看看