how to dynamically add rows?

2 posts, 0 answers
  1. Patrick
    Patrick avatar
    14 posts
    Member since:
    Feb 2011

    Posted 12 Apr 2011 Link to this post

    I always get a nullreference exception in the report designer. I just copied the code from the InitializeComponent method and modified it to my needs.

    private Table CreateTable()
           {
               Table table1 = new Table();
               table1.Name = "table1";
               //important!
               table1.RowGroups.Clear();
               table1.ColumnGroups.Clear();
               table1.Body.Columns.Clear();
               table1.Body.Rows.Clear();
     
               this.detail.Items.AddRange(new Telerik.Reporting.ReportItemBase[] {
               table1});
               table1.Size = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(15.199901580810547D, Telerik.Reporting.Drawing.UnitType.Cm), new Telerik.Reporting.Drawing.Unit(0.99999994039535522D, Telerik.Reporting.Drawing.UnitType.Cm));
               table1.Location = new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(0, Telerik.Reporting.Drawing.UnitType.Cm), new Telerik.Reporting.Drawing.Unit(0, Telerik.Reporting.Drawing.UnitType.Cm));
                
               TableGroup grpPos = new TableGroup();
               TableGroup grpCount = new TableGroup();
               TableGroup grpArtName = new TableGroup();
               TableGroup grpLaufzeit = new TableGroup();
               TableGroup grpPrice = new TableGroup();
     
               table1.Body.Columns.Add(new Telerik.Reporting.TableBodyColumn(Unit.Cm(1)));
               table1.Body.Columns.Add(new Telerik.Reporting.TableBodyColumn(Unit.Cm(1)));
               table1.Body.Columns.Add(new Telerik.Reporting.TableBodyColumn(Unit.Cm(1)));
               table1.Body.Columns.Add(new Telerik.Reporting.TableBodyColumn(Unit.Cm(1)));
               table1.Body.Columns.Add(new Telerik.Reporting.TableBodyColumn(Unit.Cm(1)));
     
     
               //CreateRows(table1);
     
               TableGroup grp = new TableGroup();
               Telerik.Reporting.TextBox txtPosValue = new Telerik.Reporting.TextBox();
               txtPosValue.Value = "=Fields.ArtikelPosition";
               txtPosValue.Name = "txtPosValue";
               txtPosValue.Size = new SizeU(Unit.Cm(1.1), Unit.Cm(0.4));
     
               table1.Body.Rows.Add(new Telerik.Reporting.TableBodyRow(new Telerik.Reporting.Drawing.Unit(1, Telerik.Reporting.Drawing.UnitType.Cm)));
               table1.Body.SetCellContent(0, 0, txtPosValue);
     
     
               table1.ColumnGroups.Add(grpPos);
               table1.ColumnGroups.Add(grpCount);
               table1.ColumnGroups.Add(grpArtName);
               table1.ColumnGroups.Add(grpLaufzeit);
               table1.ColumnGroups.Add(grpPrice);
     
               Telerik.Reporting.TextBox textboxGroupPos = new Telerik.Reporting.TextBox();
               textboxGroupPos.Value = "Pos.";
               textboxGroupPos.Size = new SizeU(Unit.Cm(1.1), Unit.Cm(0.4));
               grpPos.ReportItem = textboxGroupPos;
     
               Telerik.Reporting.TextBox textboxGroupCount = new Telerik.Reporting.TextBox();
               textboxGroupCount.Value = "Menge";
               textboxGroupCount.Size = new SizeU(Unit.Cm(1.5), Unit.Cm(0.4));
               grpCount.ReportItem = textboxGroupCount;
     
               Telerik.Reporting.TextBox textboxGroupArtName = new Telerik.Reporting.TextBox();
               textboxGroupArtName.Value = "Bezeichnung";
               textboxGroupArtName.Size = new SizeU(Unit.Cm(6.5), Unit.Cm(0.4));
               grpArtName.ReportItem = textboxGroupArtName;
     
               Telerik.Reporting.TextBox textboxGroupLaufzeit = new Telerik.Reporting.TextBox();
               textboxGroupLaufzeit.Value = "Laufzeit";
               textboxGroupLaufzeit.Size = new SizeU(Unit.Cm(3.5), Unit.Cm(0.4));
               grpLaufzeit.ReportItem = textboxGroupLaufzeit;
     
               Telerik.Reporting.TextBox textboxGroupPrice = new Telerik.Reporting.TextBox();
               textboxGroupPrice.Value = "Preis / Monat";
               textboxGroupPrice.Size = new SizeU(Unit.Cm(2.4), Unit.Cm(0.4));
               grpPrice.ReportItem = textboxGroupPrice;
     
               //table1.Items.AddRange(new Telerik.Reporting.ReportItemBase[] {
               //textboxGroupPos,textboxGroupCount,textboxGroupArtName,textboxGroupLaufzeit,textboxGroupPrice,txtPosValue});
     
               grp.Groupings.AddRange(new Telerik.Reporting.Data.Grouping[] {
               new Telerik.Reporting.Data.Grouping("")});
     
               grp.Name = "DetailGroup";
               table1.RowGroups.Add(grp);
     
               return table1;
           }

    thx 4 help
  2. Massimiliano Bassili
    Massimiliano Bassili avatar
    323 posts
    Member since:
    May 2006

    Posted 15 Apr 2011 Link to this post

    The structure of the Table item is not trivial, so good understanding of the Table API is required. If you're not sure what you're doing make the changes to the table in the report designer and then use the code.

    Cheers!
  3. DevCraft banner
Back to Top