Register a BO programmatically doesnt really work!
I want to create a BO with nested Lists, fillt it with some data, register the BO, run the designer with a newly created report and see my
ready-to-use registered BO-Tree. But FR doesn't get the *nested* Objects automatically. I have to choose them manually (which is no option for me).
// The simple class-hierarchy:
Then i have to do this manually:
Then its ok:
Here's the correct frx-Xml (after manually selecting all nested objects):
Here's the wrong frx-Xml (after opening in the way described above) :
ready-to-use registered BO-Tree. But FR doesn't get the *nested* Objects automatically. I have to choose them manually (which is no option for me).
// The simple class-hierarchy:
public class Master {
public string Name { get; set; }
public List<Child> Children { get; set; }
}
public class Child {
public string Name { get; set; }
public List<SubChild> SubChildren { get; set; }
}
public class SubChild {
public string Name { get; set; }
}
// Create a Sample-BO:
private Master CreateMaster()
{
return new Master() {Name = "master",
Children = new List<Child>
{new Child {Name = "child-1",
SubChildren = new List<SubChild>
{new SubChild {Name = "subchild-1-1"},
new SubChild {Name = "subchild-1-2"}}},
new Child {Name = "child-2",
SubChildren = new List<SubChild>
{new SubChild {Name = "subchild-2-1"},
new SubChild {Name = "subchild-2-2"}}}
}};
}
//Run it:
void Go() {
using (FastReport.Report report = new FastReport.Report())
{
report.Dictionary.RegisterData(new Master[] {CreateMaster()}, "MyMaster", true);
report.Design();
}
}
First i just see this:Then i have to do this manually:
Then its ok:
Here's the correct frx-Xml (after manually selecting all nested objects):
<Dictionary>
<BusinessObjectDataSource Name="MyMaster" ReferenceName="MyMaster" DataType="FastReport1.Master[], FastReport1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" Enabled="true">
<Column Name="Name" DataType="System.String"/>
<BusinessObjectDataSource Name="Children" DataType="System.Collections.Generic.List`1[[FastReport1.Child, FastReport1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]" Enabled="true">
<Column Name="Name" DataType="System.String"/>
<BusinessObjectDataSource Name="SubChildren" DataType="System.Collections.Generic.List`1[[FastReport1.SubChild, FastReport1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]" Enabled="true">
<Column Name="Name" DataType="System.String"/>
</BusinessObjectDataSource>
</BusinessObjectDataSource>
</BusinessObjectDataSource>
</Dictionary>
Here's the wrong frx-Xml (after opening in the way described above) :
<Dictionary>
<BusinessObjectDataSource Name="MyMaster" ReferenceName="MyMaster" DataType="FastReport1.Master[], FastReport1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" Enabled="true">
<Column Name="Name" DataType="System.String"/>
<BusinessObjectDataSource Name="Children" Enabled="false" DataType="System.Collections.Generic.List`1[[FastReport1.Child, FastReport1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]"/>
</BusinessObjectDataSource>
</Dictionary>
So, is there any way to achieve my goal? (I really don't want to implement the worst work-around ever: Read my BOs via reflection, build the Dictionary-Node on my own and modify the frx-Xml...)
Comments
Use this code to register nested data: