2016-03-31 44 views
1

我在項目中使用了devexpress xtrareports v.15 for winforms。如何從文件加載devexpress xtrareport並連接數據

我有發票報告。它裏面有一些文本字段和一個列表。我的數據連接到源在報告中構造函數:

public InvoiceReport(InvoiceCommonData icd, List<ReportPosition> positions) 
    {    
     InitializeComponent();    
     this.ReportCommonDataSource.DataSource = icd; 
     this.positionsList.DataSource = positions;    
    } 

當我打印報告,因爲它是在Visual Studio中創建的數據連接正道。 但我需要爲此報告加載不同的佈局。我存儲報告佈局repx文件,並嘗試從文件在運行時加載它:

InvoiceReport report = new InvoiceReport(model.GetCommonData(), model.GetPositions()); 
var filename = "D://InvoiceReport.repx"; 
report.LoadLayout(filename); 

當我打印的報告中,我看到,常見的數據(icd)結合,並打印,但名單(positions)沒有約束,它是空表而不是實際數據。 問題是如何從文件加載xtrareport佈局並保存所有數據連接?

回答

0

但我想你可以嘗試替換默認repx文件連接到你的主要連接becouse,當我們從報表設計器創建repx文件時,我們設置連接和repx保存爲默認,當我們嘗試預覽報告與查看器文件獲取默認保存連接,所以嘗試從所需的sql連接替換連接。

like if (((DevExpress.DataAccess.Sql.SqlDataSource)devxReport.DataSource).ConnectionParameters != null) //change if connection exists in report { ((DevExpress.DataAccess.Sql.SqlDataSource)devxReport.DataSource).ConnectionParameters = null; } ((DevExpress.DataAccess.Sql.SqlDataSource)devxReport.DataSource).ConnectionParameters = new DevExpress.DataAccess.ConnectionParameters.CustomStringConnectionParameters(sqlConnectionString);

+0

Lalit Sharma謝謝你的回答。我的問題是,當我從文件加載佈局報告不顯示列表。當我不加載佈局時,它應該像它應該那樣工作。 –

相關問題