将多个对象设置为水晶报表的数据源
我想在我的c#windows应用程序中制作一个水晶报告,关键是我想使用.net对象作为我的报告数据源,我在互联网上找到它的示例代码如下并使用它们并且它工作正常:
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作为水晶报表的数据源。
如果您有许多数据源,例如1.EmployeeClass 2.EmpployeeSkillClass
请执行下列操作 :
List employeeList = new List (); employeeList.Add(new EmployeeClass() { EmpNo = "001", EmpName = "Supitchaya" }); List employeeSkillList = new List (); detList.Add(new EmpployeeSkillClass() { EmpNo = "001", Skill="C#" }); detList.Add(new EmpployeeSkillClass() { EmpNo = "001", Skill="Java" });
//创建ReportDocument的即时消息:
ReportDocument report = new RptEmployee(); //Crsytal report file
//将数据源设置为每个表。 确保收集每个表的索引
//(在调试模式下运行,找到类型为Employee或EmployeeSkill的表[0]映射)
report.Database.Tables[0].SetDataSource(employeeList ); report.Database.Tables[1].SetDataSource(employeeSkillList ); crystalReportViewer1.ReportSource = report;
//完!!
在设计模式下执行此操作时,它会告诉您它不受支持。
也许在数据源之间有一个外部参照…