This is a migrated thread and some comments may be shown as answers.

how to dynamically add rows?

1 Answer 410 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 1
Patrick asked on 12 Apr 2011, 01:33 PM
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

1 Answer, 1 is accepted

Sort by
0
Massimiliano Bassili
Top achievements
Rank 1
answered on 15 Apr 2011, 04:49 PM
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!
Tags
General Discussions
Asked by
Patrick
Top achievements
Rank 1
Answers by
Massimiliano Bassili
Top achievements
Rank 1
Share this question
or