Hi,
I am trying to create a report that includes a table dynamically generated, I will not use the viewer control, just I would like to generate the table from a DataTable but after compose the with the method "GenerateTable" and save the file I always get the error "An error has occurred while processing Table 'xxxx':
Table Body has 2 rows but 0 are expected"
What is wrong?, any help would be appreciated.
namespace ReportLibrary{ partial class GenericReport { #region Component Designer generated code /// <summary> /// Required method for telerik Reporting designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { Telerik.Reporting.Drawing.StyleRule styleRule1 = new Telerik.Reporting.Drawing.StyleRule(); this.pageHeaderSection1 = new Telerik.Reporting.PageHeaderSection(); this.detail = new Telerik.Reporting.DetailSection(); this.pageFooterSection1 = new Telerik.Reporting.PageFooterSection(); ((System.ComponentModel.ISupportInitialize)(this)).BeginInit(); // // pageHeaderSection1 // this.pageHeaderSection1.Height = Telerik.Reporting.Drawing.Unit.Inch(1D); this.pageHeaderSection1.Name = "pageHeaderSection1"; // // detail // this.detail.Height = Telerik.Reporting.Drawing.Unit.Inch(2D); this.detail.Name = "detail"; // // pageFooterSection1 // this.pageFooterSection1.Height = Telerik.Reporting.Drawing.Unit.Inch(1D); this.pageFooterSection1.Name = "pageFooterSection1"; // // GenericReport // this.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { this.pageHeaderSection1, this.detail, this.pageFooterSection1}); this.Name = "GenericReport"; this.PageSettings.Margins = new Telerik.Reporting.Drawing.MarginsU(Telerik.Reporting.Drawing.Unit.Inch(1D), Telerik.Reporting.Drawing.Unit.Inch(1D), Telerik.Reporting.Drawing.Unit.Inch(1D), Telerik.Reporting.Drawing.Unit.Inch(1D)); this.PageSettings.PaperKind = System.Drawing.Printing.PaperKind.Letter; styleRule1.Selectors.AddRange(new Telerik.Reporting.Drawing.ISelector[] { new Telerik.Reporting.Drawing.TypeSelector(typeof(Telerik.Reporting.TextItemBase)), new Telerik.Reporting.Drawing.TypeSelector(typeof(Telerik.Reporting.HtmlTextBox))}); styleRule1.Style.Padding.Left = Telerik.Reporting.Drawing.Unit.Point(2D); styleRule1.Style.Padding.Right = Telerik.Reporting.Drawing.Unit.Point(2D); this.StyleSheet.AddRange(new Telerik.Reporting.Drawing.StyleRule[] { styleRule1}); this.Width = Telerik.Reporting.Drawing.Unit.Inch(6.125D); ((System.ComponentModel.ISupportInitialize)(this)).EndInit(); } #endregion private Telerik.Reporting.PageHeaderSection pageHeaderSection1; private Telerik.Reporting.DetailSection detail; private Telerik.Reporting.PageFooterSection pageFooterSection1; }}
namespace ReportLibrary{ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Windows.Forms; using Telerik.Reporting; using Telerik.Reporting.Drawing; /// <summary> /// Summary description for GenericReport /// </summary> public partial class GenericReport : Telerik.Reporting.Report { private DataSet dataSet; public GenericReport(DataSet dataSet) { // // Required for telerik Reporting designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // foreach (DataTable dataTable in dataSet.Tables) { Telerik.Reporting.Table table = null; table = GenerateTable(dataTable); this.detail.Items.Add(table); } } private Telerik.Reporting.Table GenerateTable(DataTable dataTable) { Telerik.Reporting.Table table = new Table(); table.Name = dataTable.TableName; //Create columns int counterColumn = 0; foreach (System.Data.DataColumn column in dataTable.Columns) { //Add column table.Body.Columns.Add(new Telerik.Reporting.TableBodyColumn(Telerik.Reporting.Drawing.Unit.Inch(1D))); //Create group to include column Telerik.Reporting.TableGroup tmpTableGroup = new Telerik.Reporting.TableGroup(); tmpTableGroup.Name = "tableGroup" + counterColumn; //Column textBox Telerik.Reporting.TextBox tmpTextBox = new Telerik.Reporting.TextBox(); tmpTextBox.Name = column.ColumnName; tmpTextBox.Value = column.ColumnName; tmpTableGroup.ReportItem = tmpTextBox; table.ColumnGroups.Add(tmpTableGroup); table.Items.Add(tmpTextBox); counterColumn++; } //Create rows int counterRow = 0; foreach (System.Data.DataRow row in dataTable.Rows) { table.Body.Rows.Add(new Telerik.Reporting.TableBodyRow(Unit.Pixel(50))); for (int i = 0; i < dataTable.Columns.Count; i++) { Telerik.Reporting.TextBox tmpTextBox = new Telerik.Reporting.TextBox(); tmpTextBox.Name = "dd"; tmpTextBox.Value = row.ItemArray[i].ToString(); tmpTextBox.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Inch(1D), Telerik.Reporting.Drawing.Unit.Inch(1D)); table.Body.SetCellContent(counterRow, i, tmpTextBox); table.Items.Add(tmpTextBox); } counterRow++; } table.Location = new Telerik.Reporting.Drawing.PointU(Telerik.Reporting.Drawing.Unit.Inch(0.20000000298023224D), Telerik.Reporting.Drawing.Unit.Inch(0.30000001192092896D)); return table; } }}