C# VS 2013 C RDLC报表无法访问类中的对象
基本上,我使用一个类Buissness对象作为数据集 我有一个名为Parent的类,它包含一个对象子对象 班级家长C# VS 2013 C RDLC报表无法访问类中的对象,c#,oop,visual-studio-2013,rdlc,C#,Oop,Visual Studio 2013,Rdlc,基本上,我使用一个类Buissness对象作为数据集 我有一个名为Parent的类,它包含一个对象子对象 班级家长 class Parent { private Child _ObjChild Public Child ObjChild { get { return this._ObjChild; } } public Parent(Child child) { this._ObjChild = child; } } 班童 class
class Parent
{
private Child _ObjChild
Public Child ObjChild { get { return this._ObjChild; } }
public Parent(Child child)
{
this._ObjChild = child;
}
}
班童
class Child
{
private string _Name;
private int _Age;
Public string Name { get { return this._Name; } }
Public string Age { get { return this._Age; } }
public Parent(string name, int age)
{
this._Name = name;
this._Age = age;
}
}
现在在rdlc报告中,我创建了一个Object类型的新数据集,并将其引用到我的父对象
以下是我加载报告的方式:
BindingSource bs = new BindingSource();
ReportDataSource rds = new ReportDataSource();
// This creates a new list of Parent() and returns it
bs.DataSource = this.CurrentReportView.GetData();
rds.Name = "dsMain";
rds.Value = bs;
this.rvMain.LocalReport.DataSources.Clear();
// This Returns the path where the report is residing
this.rvMain.LocalReport.ReportPath = this.CurrentReportView.GetReportFilePath();
this.rvMain.LocalReport.DataSources.Add(rds);
this.rvMain.RefreshReport();
一切都正常工作,除了当我想显示我的ObjChild时,它会打印出一个错误我正在尝试访问我的ObjChild的属性Age或Name,但我似乎不知道如何操作。经过长时间的搜索,我找不到获取子对象数据的解决方案,但我找到了解决方法 我所做的只是将我的childobjects属性暴露到另一个名为ChildProperties的调用中
class ChildProperties
{
private Parent _ObjParent;
// Exposing the Parent (if needed) and Child properties
public string Name{ get { return this._ObjParent.ObjChild.Name; } }
public intAge { get { return this._ObjParent.ObjChild.Age; } }
public Parent(Parent parent)
{
this._ObjParent = parent;
}
}
然后,我使用这个新类创建一个新的对象数据集,并公开所需的属性