将多个对象设置为水晶报表的数据源
问题描述:
我想在我的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用作水晶报表的数据源。
答
当您在设计模式下执行此操作时,它会告诉您它不受支持。
与数据源之间的外部参照也许......
答
如果您有许多数据源,如 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;
//完成!
我想知道你是否有一个想法,为什么我的报告是空的 – Enzero 2012-10-04 13:32:28
非常感谢你,你救了我的生命:)) – ertan2002 2013-05-19 14:07:04
@Enzero我刚刚看到你的问题。我想你可能会有答案。抱歉回复晚了 – Supitchaya 2013-06-27 10:09:29