VS 2010报告查看器不能访问嵌套集合,有人吗?

时间:2021-02-24 08:21:08

I have gone through all the walk through on MSDN as usual they are worthless - extremely limited.

我像往常一样在MSDN上经历了所有的过程,它们毫无价值——极其有限。

If I make the internal object in my class a single class I can display the information, but as soon as I convert it to a list of objects ( a collection ) I get the #Error in the display.

如果我将类中的内部对象设置为单个类,我就可以显示信息,但是一旦我将其转换为对象列表(集合),就会在显示中得到#Error。

Here is an updated example.

这里有一个更新的例子。

For an example I have a Person object that can have one or more phone numbers ( list of numbers ) and I cannot find a way to access the phone numbers.

例如,我有一个Person对象,该对象可以有一个或多个电话号码(号码列表),我无法找到访问电话号码的方法。

[Serializable]
public class Person
{
    private readonly List<PhoneNumber> _numbers = new List<PhoneNumber>();

    public Person()
    {
    }

    public Person(int id, string name, string address, decimal salary)
    {
        Id = id;
        Name = name;
        Address = address;
        Salary = salary;
    }

    public void AddNumber(PhoneNumber number)
    {
        _numbers.Add(number);            
    }


    public int Id { get; set; }
    public string Name { get; set; }
    public string Address { get; set; }

    public List<PhoneNumber> PhoneNumbers { get { return _numbers; } }       

}

[Serializable]
public class PhoneNumber
{
    public PhoneNumber()
    {
    }

    public PhoneNumber(int id, string areaCode, string phone)
    {
        AreaCode = areaCode;
        Id = id;
        Phone = phone;
    }

    public string AreaCode { get; set; }
    public string Phone { get; set; }
    public int Id { get; set; }
}

I then populate the collections.

然后填充集合。

    var persons = new List<Person>();

    var t = new Person(1, "Mike", "5150 Nuts", 125);

    t.AddNumber(new PhoneNumber(1, "425", "455"));
    t.AddNumber(new PhoneNumber(1, "425", "450"));

    persons.Add(t);

    t = new Person(2, "Tom", "1055 MS HAS NO DOCUMENTATION AS USUAL!", 1245);

    t.AddNumber(new PhoneNumber(2, "TYPICAL", "OF-THEM"));
    t.AddNumber(new PhoneNumber(2, "ANY", "ONE???"));

    persons.Add(t);

I then assign everything to the report.

然后我把所有的东西都分配给报告。

    reportViewer1.ProcessingMode = ProcessingMode.Local;
    reportViewer1.LocalReport.ReportPath = "..\\..\\Report1.rdlc";
    reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("Person",persons));
    reportViewer1.RefreshReport();

In the report it displays the people will display without issue as I add the text boxes to a list and then group the list by Id. When I try to display the phone numbers, I get the #ERROR message, and for the life of me I cannot seem to find a way to display the list of numbers that are assigned to a person.

在报告中显示了人们将显示没有问题我将文本框添加到一个列表,然后组通过Id列表。当我试图显示电话号码,我让#错误消息,似乎我的生活我不能找到一种方法来显示数字的列表分配给一个人。

If I change the object from List<PhoneNumber> within the person class to PhoneNumber I can access it, but when trying to display a List<PhoneNumber> I cant.

如果我将person类中的List 对象更改为PhoneNumber,我可以访问它,但是当试图显示列表 时,我不能。

I need to be ale to display List<of objects> within an Class Item.

我需要是ale才能在类项中显示对象的列表< >。

1 个解决方案

#1


2  

The nested collection must be displayed as a subreport where the nested collection is an separate data source. You must bind the event LocalReport.SubreportProcessing to a handler that will filter and bind the datasource (PhoneNumbers) to the subreport as a seperate report data source. The example at the link provided should get you where you need to go.

嵌套集合必须显示为子报表,其中嵌套集合是单独的数据源。您必须绑定事件LocalReport。将筛选并将数据源(PhoneNumbers)作为独立报表数据源绑定到子报表的处理程序的SubreportProcessing。在提供的链接上的示例应该可以让您知道需要去哪里。

#1


2  

The nested collection must be displayed as a subreport where the nested collection is an separate data source. You must bind the event LocalReport.SubreportProcessing to a handler that will filter and bind the datasource (PhoneNumbers) to the subreport as a seperate report data source. The example at the link provided should get you where you need to go.

嵌套集合必须显示为子报表,其中嵌套集合是单独的数据源。您必须绑定事件LocalReport。将筛选并将数据源(PhoneNumbers)作为独立报表数据源绑定到子报表的处理程序的SubreportProcessing。在提供的链接上的示例应该可以让您知道需要去哪里。