前兩種方法和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;
- in the current assembly where the FromFile method is called from;
- 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中傳遞參數的方法也可以實現使用者自訂報表。