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:
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:
fr-problem-screenshot-02.jpg

Then i have to do this manually:
fr-problem-screenshot-03.jpg
fr-problem-screenshot-04.jpg

Then its ok:
fr-problem-screenshot-01.jpg

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

  • edited 1:21PM
    Hello,

    Use this code to register nested data:
    report.RegisterData(new Master[] {CreateMaster()}, "MyMaster", 5); // 5 is max.nesting level
    report.GetDataSource("MyMaster").Enabled = true;
    
  • edited November 2011
    AlexTZ wrote: »
    Hello,

    Use this code to register nested data:
    report.RegisterData(new Master[] {CreateMaster()}, "MyMaster", 5); // 5 is max.nesting level
    report.GetDataSource("MyMaster").Enabled = true;
    
    Thank you for your fast reply. That works fine! (I had already tried the first line of your 2-lines-solution, but didn't know, that i had to enable the datasource explicitly after registering it...)

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.