動態傳遞參數到DevExpress.XtraReports的小結 .

來源:互聯網
上載者:User

前兩種方法和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中傳遞參數的方法也可以實現使用者自訂報表。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.