Creating tables from code

edited August 2012 in FastReport .NET
Hello,

I have been working on it couple days already, tried to make a documentation report. First I created 2 tables inside Page1 tab. It's working. Im reading data from database. Every model item should have 1 table for Description this item and 2nd with models elements. But with that solution I get 2 tables, 1s table with all model items and 2nd with all model elements mixed all in one table.

Then I tried to add an instance for new table inside code tab to create new table everytime we go into FOR or FOREACH clauses but nothing really printed. So my question is how do create table like that and create a new table everytime we go into the FOR or FOREACH clauses to print every new table for new item from this model and new table for elements of this item model?

Here is the code:
private void Data1_BeforePrint(object sender, EventArgs e)
    {                               
      DataSourceBase ds = Report.GetDataSource("listaSlownikow");
      
      if (ds != null)
      {    
        ds.Init();
        Font naglowek = new Font("Times New Roman", 10);
        for (int i = 1; i < ds.RowCount; i++)
        {         
          ds.CurrentRowNo = i;
          SlownikProsty ow = (SlownikProsty) ds.CurrentRow;
          TableObject Table1=new TableObject();
          Table1.ColumnCount=2;
          Table1.RowCount=8;
          TableRow tr1 = new TableRow();
          tr1.AutoSize = true;
          TableCell tc1 = new TableCell();
          tc1.Border.Lines = BorderLines.All;
          tc1.Text = "Kod";
          tc1.Font = naglowek;
          tc1.VertAlign = VertAlign.Center;
          tc1.HorzAlign = HorzAlign.Left;
          tr1.AddChild(tc1);
          tc1 = new TableCell();
          tc1.Border.Lines = BorderLines.All;
          if(ow.Kod!=null)
          {
            tc1.Text = ow.Kod;
          }
          else
          {
            tc1.Text="";
          }
          tc1.Font = naglowek;
          tc1.VertAlign = VertAlign.Center;
          tc1.HorzAlign = HorzAlign.Left;
          tr1.AddChild(tc1);
          
          Table1.AddChild(tr1);
          
          TableRow tr2 = new TableRow();
          tr2.AutoSize = true;
          TableCell tc2 = new TableCell();
          tc2.Border.Lines = BorderLines.All;
          tc2.Text = "Grupa";
          tc2.Font = naglowek;
          tc2.VertAlign = VertAlign.Center;
          tc2.HorzAlign = HorzAlign.Left;
          tr2.AddChild(tc2);
          tc2 = new TableCell();
          tc2.Border.Lines = BorderLines.All;
          if(ow.Grupa!=null)
          {
            tc2.Text = ow.Grupa;
          }
          else
          {
            tc2.Text="";
          }
          tc2.Font = naglowek;
          tc2.VertAlign = VertAlign.Center;
          tc2.HorzAlign = HorzAlign.Left;
          tr2.AddChild(tc2);
          Table1.AddChild(tr2);
          
          TableRow tr3 = new TableRow();
          tr3.AutoSize = true;
          TableCell tc3 = new TableCell();
          tc3.Border.Lines = BorderLines.All;
          tc3.Text = "Opis:";
          tc3.Font = naglowek;
          tc3.VertAlign = VertAlign.Center;
          tc3.HorzAlign = HorzAlign.Left;
          tr3.AddChild(tc3);
          tc3 = new TableCell();
          tc3.Border.Lines = BorderLines.All;
          if(ow.Opis !=null)
          {
            tc3.Text = ow.Opis;
          }
          else
          {
            tc3.Text = ""; 
          }
          tc3.Font = naglowek;
          tc3.VertAlign = VertAlign.Center;
          tc3.HorzAlign = HorzAlign.Left;
          tr3.AddChild(tc3);
          Table1.AddChild(tr3);  
          
          TableRow tr4 = new TableRow();
          tr4.AutoSize = true;
          TableCell tc4 = new TableCell();
          tc4.Border.Lines = BorderLines.All;
          tc4.Text = "Opis słownika powiązanego:";
          tc4.Font = naglowek;
          tc4.VertAlign = VertAlign.Center;
          tc4.HorzAlign = HorzAlign.Left;
          tr4.AddChild(tc4);
          tc4 = new TableCell();
          tc4.Border.Lines = BorderLines.All;
          if(ow.OpisSlownikaPowiazanego!=null)
          {
            tc4.Text = ow.OpisSlownikaPowiazanego;
          } 
          else
          {
            tc4.Text="";
          }
          tc4.Font = naglowek;
          tc4.VertAlign = VertAlign.Center;
          tc4.HorzAlign = HorzAlign.Left;
          tr4.AddChild(tc4);
          Table1.AddChild(tr4);
          
          TableRow tr5 = new TableRow();
          tr5.AutoSize = true;
          TableCell tc5 = new TableCell();
          tc5.Border.Lines = BorderLines.All;
          tc5.Text = "Opis wyr??żnika 1:";
          tc5.Font = naglowek;
          tc5.VertAlign = VertAlign.Center;
          tc5.HorzAlign = HorzAlign.Left;
          tr5.AddChild(tc5);
          tc5 = new TableCell();
          tc5.Border.Lines = BorderLines.All;
          if (ow.OpisWyroznik1!=null)
          {
            tc5.Text = ow.OpisWyroznik1;
          }
          else
          {
            tc5.Text=""; 
          }
          tc5.Font = naglowek;
          tc5.VertAlign = VertAlign.Center;
          tc5.HorzAlign = HorzAlign.Left;
          tr5.AddChild(tc5);
          Table1.AddChild(tr5);
          
          TableRow tr6 = new TableRow();
          tr6.AutoSize = true;
          TableCell tc6 = new TableCell();
          tc6.Border.Lines = BorderLines.All;
          tc6.Text = "Opis wyr??żnika 2:";
          tc6.Font = naglowek;
          tc6.VertAlign = VertAlign.Center;
          tc6.HorzAlign = HorzAlign.Left;
          tr6.AddChild(tc6);
          tc6 = new TableCell();
          tc6.Border.Lines = BorderLines.All;     
          if (ow.OpisWyroznik2!=null)
          {
            tc6.Text = ow.OpisWyroznik2;
          }
          else
          {
            tc6.Text=""; 
          }
          tc6.Font = naglowek;
          tc6.VertAlign = VertAlign.Center;
          tc6.HorzAlign = HorzAlign.Left;
          tr6.AddChild(tc6);
          Table1.AddChild(tr6);
          
          TableRow tr7 = new TableRow();
          tr7.AutoSize = true;
          TableCell tc7 = new TableCell();
          tc7.Border.Lines = BorderLines.All;
          tc7.Text = "Opis wyr??żnika 3:";
          tc7.Font = naglowek;
          tc7.VertAlign = VertAlign.Center;
          tc7.HorzAlign = HorzAlign.Left;
          tr7.AddChild(tc7);
          tc7 = new TableCell();
          tc7.Border.Lines = BorderLines.All;   
          if (ow.OpisWyroznik3!=null)
          {
            tc7.Text = ow.OpisWyroznik3;
          }
          else
          {
            tc7.Text=""; 
          }
          tc7.Font = naglowek;
          tc7.VertAlign = VertAlign.Center;
          tc7.HorzAlign = HorzAlign.Left;
          tr7.AddChild(tc7);
          Table1.AddChild(tr7);

          TableObject Table2=new TableObject();
          Table2.ColumnCount=2;
          Table2.RowCount=8;
          TableRow tr8 = new TableRow();
          tr8.AutoSize = true;
          TableCell tc8 = new TableCell();
          tc8.Border.Lines = BorderLines.All;
          tc8.Text = "Kod";
          tc8.Font = naglowek;
          tc8.VertAlign = VertAlign.Center;
          tc8.HorzAlign = HorzAlign.Left;
          tr8.AddChild(tc8);
          tc8 = new TableCell();
          tc8.Border.Lines = BorderLines.All;
          tc8.Text = "Opis";
          tc8.Font = naglowek;
          tc8.VertAlign = VertAlign.Center;
          tc8.HorzAlign = HorzAlign.Left;
          tr8.AddChild(tc8);
          tc8 = new TableCell();
          tc8.Border.Lines = BorderLines.All;
          tc8.Text = "Sort.";
          tc8.Font = naglowek;
          tc8.VertAlign = VertAlign.Center;
          tc8.HorzAlign = HorzAlign.Left;
          tr8.AddChild(tc8);
          tc8 = new TableCell();
          tc8.Border.Lines = BorderLines.All;
          tc8.Text = "Akt.";
          tc8.Font = naglowek;
          tc8.VertAlign = VertAlign.Center;
          tc8.HorzAlign = HorzAlign.Left;
          tr8.AddChild(tc8);
          tc8 = new TableCell();
          tc8.Border.Lines = BorderLines.All;
          tc8.Text = "Kod sł. pow.";
          tc8.Font = naglowek;
          tc8.VertAlign = VertAlign.Center;
          tc8.HorzAlign = HorzAlign.Left;
          tr8.AddChild(tc8);
          tc8 = new TableCell();
          tc8.Border.Lines = BorderLines.All;
          tc8.Text = "Wyr1";
          tc8.Font = naglowek;
          tc8.VertAlign = VertAlign.Center;
          tc8.HorzAlign = HorzAlign.Left;
          tr8.AddChild(tc8);
          tc8 = new TableCell();
          tc8.Border.Lines = BorderLines.All;
          tc8.Text = "Wyr2";
          tc8.Font = naglowek;
          tc8.VertAlign = VertAlign.Center;
          tc8.HorzAlign = HorzAlign.Left;
          tr8.AddChild(tc8);
          tc8 = new TableCell();
          tc8.Border.Lines = BorderLines.All;
          tc8.Text = "Wyr3";
          tc8.Font = naglowek;
          tc8.VertAlign = VertAlign.Center;
          tc8.HorzAlign = HorzAlign.Left;
          tr8.AddChild(tc8);
          Table2.AddChild(tr8); 
          
          foreach(Element ele in ow.Elementy)
          {
            TableRow tr9 = new TableRow();
            tr9.AutoSize = true;
            TableCell tc9 = new TableCell();
            tc9.Border.Lines = BorderLines.All;
            if(ele.KodElementu!=null)
            {
              tc9.Text = ele.KodElementu;
            }
            else
            {
              tc9.Text="";
            }
            tc9.Font = naglowek;
            tc9.VertAlign = VertAlign.Center;
            tc9.HorzAlign = HorzAlign.Left;
            tr9.AddChild(tc9);
            tc9 = new TableCell();
            tc9.Border.Lines = BorderLines.All;
            if(ele.Opis!=null)
            {
              tc9.Text = ele.Opis;
            }
            else
            {
              tc9.Text="";
            }
            tc9.Font = naglowek;
            tc9.VertAlign = VertAlign.Center;
            tc9.HorzAlign = HorzAlign.Left;
            tr9.AddChild(tc9);
            tc9 = new TableCell();
            tc9.Border.Lines = BorderLines.All;
            if(ele.Kolejnosc!=null)
            {
              tc9.Text = ele.Kolejnosc;
            
            }
            else
            {
              tc9.Text="";
            }
            tc9.Font = naglowek;
            tc9.VertAlign = VertAlign.Center;
            tc9.HorzAlign = HorzAlign.Left;
            tr9.AddChild(tc9);
            tc9 = new TableCell();
            tc9.Border.Lines = BorderLines.All;
            if(ele.Aktywny!=null)
            {
              tc9.Text = ele.Aktywny.ToString();
            }
            else
            {
              tc9.Text="";
            }
            tc9.Font = naglowek;
            tc9.VertAlign = VertAlign.Center;
            tc9.HorzAlign = HorzAlign.Left;
            tr9.AddChild(tc9);
            tc9 = new TableCell();
            tc9.Border.Lines = BorderLines.All;
            if(ele.KodSlownikaPowiazanego!=null)
            {
              tc9.Text = ele.KodSlownikaPowiazanego;
            }
            else
            {
              tc9.Text="";
            }
            tc9.Font = naglowek;
            tc9.VertAlign = VertAlign.Center;
            tc9.HorzAlign = HorzAlign.Left;
            tr9.AddChild(tc9);
            tc9 = new TableCell();
            tc9.Border.Lines = BorderLines.All;
            if(ele.Wyroznik1!=null)
            {
              tc9.Text = ele.Wyroznik1;
            }
            else
            {
              tc9.Text="";
            }
            tc9.Font = naglowek;
            tc9.VertAlign = VertAlign.Center;
            tc9.HorzAlign = HorzAlign.Left;
            tr9.AddChild(tc9);
            tc9 = new TableCell();
            tc9.Border.Lines = BorderLines.All;
            if(ele.Wyroznik2!=null)
            {       
              tc9.Text = ele.Wyroznik2;
            }
            else
            {
              tc9.Text="";
            }
            tc9.Font = naglowek;
            tc9.VertAlign = VertAlign.Center;
            tc9.HorzAlign = HorzAlign.Left;
            tr9.AddChild(tc9);
            tc9 = new TableCell();
            tc9.Border.Lines = BorderLines.All;
            if(ele.Wyroznik3!=null)
            {
              tc9.Text = ele.Wyroznik3;
            }
            else
            {
              tc9.Text="";
            }
            tc9.Font = naglowek;
            tc9.VertAlign = VertAlign.Center;
            tc9.HorzAlign = HorzAlign.Left;
            tr9.AddChild(tc9);
            Table2.AddChild(tr9);
           
          }
        }
      }
    }

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.