動態傳遞參數到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中傳遞參數的方法也可以實現用戶自定義報表。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM