2010-05-26 38 views
7

我想在我的c#windows應用程序中創建一個水晶報表,重點是我想使用.net對象作爲我的報表數據源,我在Internet中找到它的示例代碼如下,並使用他們工作得很好:將多個對象設置爲水晶報表的數據源

 ArrayList Mainlst = new ArrayList(); 
     Mainlst.Add(new testOBJ { Firstname = "test1", Lastname = "test11" }); 
     Mainlst.Add(new testOBJ { Firstname = "test2", Lastname = "test21" }); 
     Mainlst.Add(new testOBJ { Firstname = "test3", Lastname = "test31" }); 
     Mainlst.Add(new testOBJ { Firstname = "test4", Lastname = "test41" }); 
     Mainlst.Add(new testOBJ { Firstname = "test5", Lastname = "test51" }); 
     testCrystalReport rpt = new testCrystalReport(); 
     rpt.SetDataSource(Mainlst); 
     crystalReportViewer1.ReportSource = rpt; 

但我想送額外的對象爲這些重複的信息,例如學校的信息,但我不能發送此額外的對象,是沒有辦法,我可以給多個對象的任何解決方案水晶報告?當然,我知道我可以將多個數據表和數據集用於水晶報表數據源,但在此我只想將對象和IEnumerables用作水晶報表的數據源。

回答

0

當您在設計模式下執行此操作時,它會告訴您它不受支持。

與數據源之間的外部參照

也許......

21

如果您有許多數據源,如 1.EmployeeClass 2.EmpployeeSkillClass

執行以下操作:

 List<EmployeeClass> employeeList = new List<EmployeeClass>(); 
     employeeList.Add(new EmployeeClass() { EmpNo = "001", EmpName = "Supitchaya" }); 

     List<EmpployeeSkillClass> employeeSkillList = new List<EmpployeeSkillClass>(); 
     detList.Add(new EmpployeeSkillClass() { EmpNo = "001", Skill="C#" }); 
     detList.Add(new EmpployeeSkillClass() { EmpNo = "001", Skill="Java" }); 

//創建ReportDocument的即時:

 ReportDocument report = new RptEmployee(); //Crsytal report file 

//將數據源設置爲每個表。確保每個表中的索引被收集

//(上調試模式下運行以查找表的[0]地圖Employee類型或EmployeeSkill)

 report.Database.Tables[0].SetDataSource(employeeList); 
     report.Database.Tables[1].SetDataSource(employeeSkillList); 

     crystalReportViewer1.ReportSource = report; 

//完成!

+0

我想知道你是否有一個想法,爲什麼我的報告是空的 – Enzero 2012-10-04 13:32:28

+2

非常感謝你,你救了我的生命:)) – ertan2002 2013-05-19 14:07:04

+0

@Enzero我剛剛看到你的問題。我想你可能會有答案。抱歉回覆晚了 – Supitchaya 2013-06-27 10:09:29