将多个对象设置为水晶报表的数据源

Moh*_*fia 9 .net c# crystal-reports

我想在我的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;
Run Code Online (Sandbox Code Playgroud)

但我想为这些重复的信息发送额外的对象,例如学校信息,但我不能发送这个额外的对象,有没有任何解决方案,我可以发送多个对象到水晶报告?当然我知道我可以使用多个数据表和数据集作为水晶报表数据源,但在这里我只想使用对象和IEnumerables作为水晶报表的数据源.

Sup*_*aya 24

如果您有许多数据源,例如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" });
Run Code Online (Sandbox Code Playgroud)

//创建ReportDocument的即时消息:

        ReportDocument report = new RptEmployee(); //Crsytal report file
Run Code Online (Sandbox Code Playgroud)

//将数据源设置为每个表.确保收集每个表的索引

//(在调试模式下运行,找到类型为Employee或EmployeeSkill的tables [0]映射)

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

        crystalReportViewer1.ReportSource = report;
Run Code Online (Sandbox Code Playgroud)

//完!!


Wan*_*tos 0

当您在设计模式下执行此操作时,它会告诉您不支持它。

也许在数据源之间有外部参照......