问题描述
我想在我的c#windows应用程序中生成一个水晶报表,要点是我想使用.net对象作为我的报表数据源,我发现它的示例代码如下在互联网和使用它们,它工作正常:
I wanna make a crystal report in my c# windows application, the point is I want to use .net objects as my report datasource, I found its sample code as below in internet and use them and it works fine:
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;
但我想发送额外的对象,例如学校的信息为这些重复的信息,但我不能发送这个额外的对象,有没有任何解决方案,我可以发送多个对象到水晶报告?当然我知道我可以使用多个datatable和dataset为一个水晶报表数据源,但在这里我只想使用对象和IEnumerables作为数据源的水晶报表。
But I want to send extra object for example school information for these repeated information, but I can't send this extra object, is there any solution that I can send multiple objects to the crystal report? Of course I know that I can use multiple datatable and dataset for a crystal report datasource but here I just want to use objects and IEnumerables as datasource of a crystal report.
推荐答案
如果您有很多数据源,如
1.EmployeeClass
2.EmpployeeSkillClass
if you have many datasource such as1.EmployeeClass2.EmpployeeSkillClass
执行以下操作: / p>
Do the following :
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的实例:
//Create instant of ReportDocument :
ReportDocument report = new RptEmployee(); //Crsytal report file
//为每个表设置数据源。请确保每个表的索引是收集
//Set datasource to each table. make sure that index of each table is collect
//(在调试模式下运行以查找具有Employee或EmployeeSkill类型的表[0]映射)
//(run on debug mode to find that tables[0] map with type Employee or EmployeeSkill)
report.Database.Tables[0].SetDataSource(employeeList );
report.Database.Tables[1].SetDataSource(employeeSkillList );
crystalReportViewer1.ReportSource = report;
//完成!
这篇关于将多个对象设置为水晶报表的数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!