How i add relations from list<t>

edited December 2020 in FastReport .NET


Hey,

i have add some DataSources from a list<t>

how can i add some relations between bak and angebotlst

it works on preview but i at runtime the fielt from the relation cant found.

      var bak = tarifcontext.Bauartklasse.ToList();

      var report = new Report();

      report.Load(Path.Combine(reportsFolder, "Antrag.frx"));

      report.AutoFillDataSet = true;

      report.RegisterData(bak, "Bauartklasse");

      report.RegisterData(angebotlst, "Angebot");

Comments

  • using System;

    using System.Collections;

    using System.Collections.Generic;

    using System.Data;    

    using FastReport.Data;


    namespace FastReport

    {

     public class BusinessObject1

     {

      public int id {get; set;}

      public string parentname {get; set;}

     }

      

     public class BusinessObject2

     {

      public int id {get; set;}

      public string childname {get; set;}

     }

      

     public class ReportScript

     {   

      private void _StartReport(object sender, EventArgs e)

      {                                       

       List<BusinessObject1> list1 = new List<BusinessObject1>();

       list1.Add(new BusinessObject1 { id = 1, parentname = "A" });

       list1.Add(new BusinessObject1 { id = 2, parentname = "B" });

       list1.Add(new BusinessObject1 { id = 3, parentname = "C" });

       List<BusinessObject2> list2 = new List<BusinessObject2>();

       list2.Add(new BusinessObject2 { id = 1, childname = "A1" });

       list2.Add(new BusinessObject2 { id = 2, childname = "B1" });

       list2.Add(new BusinessObject2 { id = 3, childname = "C1" });

       list2.Add(new BusinessObject2 { id = 1, childname = "A2" });

       list2.Add(new BusinessObject2 { id = 2, childname = "B2" });

       list2.Add(new BusinessObject2 { id = 3, childname = "C2" });

       Report.RegisterData(list1, "Table1");

       Report.RegisterData(list2, "Table2");

       Relation relation = new Relation()

       {

        Name = "Table1_Table2",

        ParentDataSource = Report.GetDataSource("Table1"),

        ChildDataSource = Report.GetDataSource("Table2"),

        ParentColumns = new string[] { "id" },

        ChildColumns = new string[] { "id" },

        Enabled = true

       };

       Report.Dictionary.Relations.Add(relation);

       Data1.DataSource = Report.GetDataSource("Table2");

       Data1.Sort.Add(new Sort("[Table2.childname]", false));

        

       Text1.Text = "[Table2.Table1.parentname]";

       Text2.Text = "[Table2.childname]";

      }

     }

    }

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.