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

"Dynamic" Table in Telerik Reports

34 Answers 1562 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 2
Tim asked on 05 Aug 2009, 09:02 PM
I've spent a considerable amount of time searching the documentation for an example and reading through other posts, but haven't found what I'm looking for, so forgive me if this is covered somewhere already, I just haven't seen it.

Basically, I'd like to create a report with a dynamic table on the report. By dynamic I mean at design time I don't necessarily know all of the fields that will be part of the dataset (the dataset is built at runtime based upon input from the user). Ideally, I would like to take my populated dataset and bind it to the report at runtime, and add, if necessary, any columns to the Telerik Reports table on the report. 

Are there any examples or demos of such a report? Is this even possible?

34 Answers, 1 is accepted

Sort by
0
Milen
Telerik team
answered on 10 Aug 2009, 11:34 AM
Hi Tim,

Yes, it is possible to create table at runtime (by code), as the only thing that the report table designer do is to write code in the InitializeComponent method of the report.

To accomplish that you need to have a good understanding of the Table/Crosstab API.
As stated in other post:
"...the easiest way to get there would be to first create the table in the report designer and use the code it generated for you in the InitializeComponent() as template.
The Table API is available in our documentation here."
So the best examples you may find are in the Report.InitializeComponent method after you play with the table/crosstab wizards and items at design time.

To create programmatically a table like the one you need, you need a static row group (to show column headers if you want to), a detail row group (which will produce rows from the datasource), and N static column groups (where each column group represents a column from your datasource and those you need to create "dynamically").

Also for such basic table consider using programmatically created TextBox items inside the detail section with appropriate width and left dock instead of creating a Table item (only in case these are the only items in the detail section).

Let us know if you need further assistance.

Regards,
Milen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Scott
Top achievements
Rank 2
answered on 24 May 2010, 07:35 PM
I'm also looking for information on how to do this as well except the link to the table API results in a website error can you please fix the link so I can research more on the Table API.

Thanks.
0
Steve
Telerik team
answered on 25 May 2010, 09:59 AM
Hi Scott,

The broken link to the API has been fixed, but note that you can always find the latest API and go through it from our online documentation here, by expanding the Reporting API section (see screenshot). I've also attached a sample project showing dynamic table creation for your convenience.

Greetings,
Steve
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Jayesh Goyani
Top achievements
Rank 2
answered on 20 Aug 2010, 11:32 AM
hi Steve

i want to create a report with a dynamically generate table on the telerik report.

i try to generate table dynamically with your sample project "autogeneratecolumnsfromtableschema.zip" but i got error which was posted in below file name is : "untitled.png".

Can u help me how can i solve this issue ?

Thanks in advance.
0
Steve
Telerik team
answered on 24 Aug 2010, 04:52 PM
Hi jayesh goyani,

Can you share what you have changed in the sample project I have attached? You can use the Visual Studio Output window for more information on the error (along with stack trace) while debugging to get to the bottom of the issue.

Best wishes,
Steve
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jayesh Goyani
Top achievements
Rank 2
answered on 27 Aug 2010, 10:27 AM
hi, Steve

Thanks for your suggestion.

i only change connection string in sample project.

Sample project work successfully when there is not any record/Data in Dataset  (it display all column header)

it gives null reference error (which was post in previuosly) when dataset have record.
0
Allen Chan
Top achievements
Rank 1
answered on 28 Aug 2010, 04:50 AM
I also tried this out and got the same exception. I just changed the connection string.

Here's the exception:

[NullReferenceException: Object reference not set to an instance of an object.]
   Telerik.Reporting.Processing.Table.CalculateColumns() +320
   Telerik.Reporting.Processing.Table.Measure(MeasureDirection dir, Graphics graphics) +767
   Telerik.Reporting.Processing.ProcessingElement.MeasureElement(MeasureDirection dir, Graphics graphics) +177
   Telerik.Reporting.Processing.ProcessingElement.Measure(MeasureDirection dir, Graphics graphics) +1488
   Telerik.Reporting.Processing.ReportSectionBase.Measure(MeasureDirection dir, Graphics graphics) +48
   Telerik.Reporting.Processing.ProcessingElement.MeasureElement(MeasureDirection dir, Graphics graphics) +177
   Telerik.Reporting.Processing.Group.MeasureElement(MeasureDirection dir, Graphics graphics) +268
   Telerik.Reporting.Processing.Report.MeasureElement(MeasureDirection dir, Graphics graphics) +409
   Telerik.Reporting.Processing.Report.MeasureElement(ProcessingElement elementToMeasure) +217
   Telerik.Reporting.Processing.Report.OnItemProcessed() +79
   Telerik.Reporting.Processing.ReportItemBase.Process(DataMember data) +625
   Telerik.Reporting.Processing.ReportProcessor.ProcessReport(IReportDocument reportDocument, IDictionary processingContext) +602
   Telerik.Reporting.Processing.ReportProcessor.RenderReport(String format, IReportDocument reportDocument, Hashtable deviceInfo, Hashtable renderingContext, CreateStream createStreamCallback) +456
   Telerik.ReportViewer.WebForms.ServerReport.Render(HttpResponse response, String format, Int32 pageIndex) +819
   Telerik.ReportViewer.WebForms.ReportPageOperation.PerformOperation(NameValueCollection urlQuery, HttpContext context) +240
   Telerik.ReportViewer.WebForms.HttpHandler.ProcessRequest(HttpContext context) +326
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
0
Steve
Telerik team
answered on 30 Aug 2010, 12:54 PM
Hi guys,

If the connectionString is the only thing you have changed, then do make sure that it is correct and the report can connect to data. If you are trying to display the reports in your actual application you should copy the connectionString from the app.config file of the class library with the reports to the configuration file of your actual application (web.config for web site/app, app.config for windows forms/wpf).

Best wishes,
Steve
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Allen Chan
Top achievements
Rank 1
answered on 30 Aug 2010, 02:31 PM
Thanks for the tip Steve. Unfortunately, it still does not work. I even renamed one of my test databases to AdventureWorks, so I didn't have to modify anything.

As Jayesh mentions, it works great when the table has no data, but when it does a NullReferenceException is thrown.

I did have to update it to Q2 2010 (4.1.10.714), from 4.0.10.329. Perhaps that could have been it?
0
Jayesh Goyani
Top achievements
Rank 2
answered on 01 Sep 2010, 08:07 AM
hi Allen Chan,
i m using this version Q2 2010 (4.1.10.714) and still get same error.
0
Allen Chan
Top achievements
Rank 1
answered on 01 Sep 2010, 08:10 AM
I see, so we are in the same situation. Did you try using it with another version?
0
Steve
Telerik team
answered on 01 Sep 2010, 09:26 AM
Hello guys,

Allen was right - it is the upgrade to the Q2 release that causes the problem since we have changed the table API a bit and my code does not work properly with these changes. I have revised my project to work properly and attached the modified project here for your convenience. Sorry for not checking this one sooner when you reported it.

Regards,
Steve
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Allen Chan
Top achievements
Rank 1
answered on 01 Sep 2010, 10:06 AM
Hi Steve,

I just tested your updated solution, and it's working great!!

Thank you very much.
0
ott
Top achievements
Rank 1
answered on 01 Sep 2010, 04:00 PM
Hi Steve,

Looks like I have the same problem with the Crosstab control.
my application works fine with 4.0.10.423 version.
I just fill the instance of the DataTable class with values, and then set:
MyCrosstabControl.DataSource = MyDataTable.
and the ReportViewer shows the data.

but after updating to 4.1.10.714 version, my ReportViewer shows only "object reference not set to an instance of an object" message.
I downloaded and reviewed your last updated solution from this topic.

Should I fill the Crosstab object with the data manually to view the data?
I mean the code like this:
this.crosstab1.Body.SetCellContent(....);
this.crosstab1.Items.AddRange(...);
?

Thank you.
0
Steve
Telerik team
answered on 02 Sep 2010, 05:06 PM
Hello ott,

Should we assume that you have created the Crosstab item through the Report Designer? If this is the case, then you should not be experiencing this problem in a first place, as the error in this thread was caused by wrong code on my end. When the Crosstab is created declaratively, the designer is responsible for the generation of the code it adds to the InitializeComponent method i.e. the designer itself cannot create corrupt code unless you have manually altered it. Try opening your report in the designer and rebuild your project after the upgrade to the new version and if you are still having problems, isolate a sample report that you can attach in a support ticket for us to review.

All the best,
Steve
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jayesh Goyani
Top achievements
Rank 2
answered on 03 Sep 2010, 01:02 PM
Hi Steve,

I used your updated solution, and it's working great!!

Thanks and Regards,
Jayesh Goyani
RadixWeb
0
Jonam
Top achievements
Rank 1
answered on 25 Nov 2010, 02:05 PM
Hi Steve,

do you got suggestions how to handle the '&' character. Your current solutions works great but when a text value has a special character it show the following error. "An error has occured while processing  HTMLTextBox".

kind regards,

Jonam

0
Steve
Telerik team
answered on 25 Nov 2010, 02:28 PM
Hi Jonam,

This problem is not relevant to the matters discussed here, so we kindly ask you to restrain from kidnapping forum threads on different subject.
A quick answer to your inquiry (which is available in the HtmlTextBox help article): the "&" character is considered special (markup delimiters), so it needs to be encoded in order to be treated as regular text i.e. the "&" character can be escaped with the "&" entity.

All the best,
Steve
the Telerik team
Get started with Telerik Reporting with numerous videos and detailed documentation.
0
Ibrahim Imam
Top achievements
Rank 1
answered on 26 Nov 2010, 05:22 PM
hello

i used your posted code as i also generate a table report depending on dynamic data.
additionally the report which has  a table item is a subreport.

i tried to fill the datasource from the parent report by using the event
private void subReport1_ItemDataBound(object sender, System.EventArgs e)
        {
            Telerik.Reporting.Processing.SubReport subReportProcessingItem = sender as Telerik.Reporting.Processing.SubReport;
            if (subReportProcessingItem != null)
            {
                TargetReportData target = subReportProcessingItem.DataObject.RawData as TargetReportData;
[...]
                    // Attach subreport datasource
                        subReportProcessingItem.InnerReport.DataSource = data.TableData();
                  
                }
           }


but the innerReport property is null. dataTableData is an DataTable as in your posted example (created manually in the [...] section from the target variable)
i used the above code before to manually create the structure of the subreport (by the time there was no table-item available in telerik reporting). this seems to be related to an assembly update as it worked before and i didn't change anything.
it doesn't work with Q2 or Q3 (which i recently installed to check if this error still occurs)

i then tried to use NeedDatasource event instead of the ItemDataBound but then the subreport ItemDataBinding event is fired before i set the datasource.

how can i set the datasource correctly for the subReport and generate the table report structure dynamically?

Another question regarding table reports:
can i use checkboxes instead of textboxes (as i have 2 types of table types) and bind to bool values?
0
Daniela
Top achievements
Rank 1
answered on 02 Nov 2011, 10:11 AM
Hi Steve,

I would like to ask u in this thread because here is where the project is posted.
do you know, or does anyone from telerik knows how to set the "rotate layout" property from the code behind in this example?
I would like to show the table in a vertical way but only when I have more than 5 columns in the dataset.

thanks in advance


kind Regards,
0
Steve
Telerik team
answered on 03 Nov 2011, 05:37 PM
Hello Daniela,

There is no rotate layout property. The option from the context menu which I told you about, converts column groups into row groups and vice versa. There is no way to change those at runtime as the whole table definition would have to be replaced/constructed the other way around. A possible solution for your case would be to check the number of records and generate the table according to this requirement.

Best wishes,
Steve
the Telerik team

Q2’11 SP1 of Telerik Reporting is available for download (see what's new). Get it today.

0
Daniela
Top achievements
Rank 1
answered on 04 Nov 2011, 09:16 AM
Hi Steve,

thanks for your help, it is very appreciated.
could u please provide me the same exame you posted, but generating the table in a vertical way.

kind regards,
0
Steve
Telerik team
answered on 04 Nov 2011, 09:56 AM
Hello Daniela,

As a reference when generating the report definition programmatically we highly recommend creating the desired Table through the Report Designer, use the Rotate Layout option and then review the code in the InitializeComponent to see the internal structure.

You may find useful the following help articles:


Best wishes,
Steve
the Telerik team

Q2’11 SP1 of Telerik Reporting is available for download (see what's new). Get it today.

0
Daniela
Top achievements
Rank 1
answered on 07 Dec 2011, 01:25 PM
ok, thank u!
0
Christopher
Top achievements
Rank 1
answered on 04 Oct 2012, 12:58 PM
Hi Steve,

I am using the code example from the autogeneratecolumnsfromtableschema sample project to dynamically create columns based on the DataSet. However, I have a subreport that I need to dynamically create as well. Do you have any recommendation on how to do that with the current code structure I have?

My code is similar to below:
int i = 0;
           foreach (DataColumn dc in ds.Tables[0].Columns)
           {
               tableGroupColumn = new Telerik.Reporting.TableGroup();
 
               this.table1.Body.Columns.Add(new Telerik.Reporting.TableBodyColumn(Unit.Inch(1)));
 
               textboxGroup = new Telerik.Reporting.TextBox();
               textboxGroup.Value = dc.ColumnName.ToString();
               textboxGroup.Size = new SizeU(Unit.Inch(1.1), Unit.Inch(0.3));
               tableGroupColumn.ReportItem = textboxGroup;
               table1.ColumnGroups.Add(tableGroupColumn);
 
               textBoxTable = new Telerik.Reporting.TextBox();
               table1.Body.SetCellContent(0, i++, textBoxTable);
               textBoxTable.Value = "=Fields." + dc.ColumnName;
           }
           Telerik.Reporting.TableGroup tableGroupRow = new Telerik.Reporting.TableGroup();
           this.table1.RowGroups.Add(tableGroupRow);
           tableGroupRow.Grouping.Add(new Telerik.Reporting.Data.Grouping());
           processingTable.DataSource = ds.Tables[0];
       }

Currently, I have the subreport added to the masterreport design but it produces the subreport tables at the bottom of the entire master report table. For each master table row, it prints the entire subreport table however many times a subreport row matches the parameter of the master row. It does this for each master row. (Used the parameter filter scheme from the following telerik site)

I think the problem may be I am using tables. I have attached an screenshot of the report it produces (sanitized).

I am hoping to have the subreport display rows under each master report row it has a parameter in common with.

Thanks,
Chris


UPDATE:

Removing the datasource from being set to both the subreport and its table has solved the problem of the repeat sub reports. Also, filtering the table has fixed the unrelated child rows from showing up. The only problem remaining is that the master report will still show all the master rows and underneath the child rows related to a particular master row. It does so for each master row. see updated screenshot

(Figured out two of the three problem thanks to this forum page)
0
Steve
Telerik team
answered on 09 Oct 2012, 11:01 AM
Hi Chris,

We're glad that you were able to figure our the cause for your repeating subreport. Both the SubReport and Table are Data Items that have separate data sources than the main report they are nested into. So in this line of thoughts, if you only have a Table item in the SubReport, you can simplify your layout by removing the SubReport and place your Table directly in the master report.

About the last problem remaining - can you elaborate what is your layout. Is the master report bound at all or you have a Table in it for the master records and use SubReport with Table for the child records? You can see the master-detail scenario from the documentation (How-To: Creating Master-Detail Reports Using SubReports) in action in our Invoice demo report. It uses a SubReport for the detail records, but the same can be accomplished with a Table. For your convenience I have attached the modified Invoice report that utilizes Table item instead.

Regards,
Steve
the Telerik team

HAPPY WITH TELERIK REPORTING? Do you feel that it is fantastic? Or easy to use? Or better than Crystal Reports? Tell the world, and help fellow developers! Write a short review about Telerik Reporting and Telerik Report Designer in Visual Studio Gallery today!

0
Bhanu
Top achievements
Rank 1
answered on 08 May 2013, 04:37 PM
Hi melin,

can you please send some sample code for this.i am searching for how to cretae tables on report on fly that is at run time.please send me some sample code to get started with.

thanks,
priyanka
0
Hadib Ahmabi
Top achievements
Rank 1
answered on 13 May 2013, 07:13 AM
0
Randhir
Top achievements
Rank 1
answered on 04 Sep 2013, 10:36 AM
i have tested update solution but getting error..please suggest me how can handle it...
0
Stef
Telerik team
answered on 05 Sep 2013, 04:58 PM
Hi Randhir,

Please take a look at this forum thread, where you have posted regarding the same question.

Regards,
Stef
Telerik

Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.

0
endbil
Top achievements
Rank 1
answered on 28 Jan 2014, 08:59 AM
Hi, how do I create a Telerik.Reporting.Table Dynamicaly?

my code:

            Telerik.Reporting.TextBox txt1 = new Telerik.Reporting.TextBox();
            Telerik.Reporting.TextBox txt2 = new Telerik.Reporting.TextBox();
            Telerik.Reporting.TextBox txt3 = new Telerik.Reporting.TextBox();
            Telerik.Reporting.TextBox txt4 = new Telerik.Reporting.TextBox();
            Telerik.Reporting.TextBox txt5 = new Telerik.Reporting.TextBox();
            Telerik.Reporting.TextBox txt6 = new Telerik.Reporting.TextBox();
            Telerik.Reporting.TextBox txtBaslik2 = new Telerik.Reporting.TextBox();
            Telerik.Reporting.Table table2 = new Telerik.Reporting.Table();
            table2.Body.Columns.Add(new Telerik.Reporting.TableBodyColumn(Telerik.Reporting.Drawing.Unit.Cm(4.9999327659606934D)));
            table2.Body.Columns.Add(new Telerik.Reporting.TableBodyColumn(Telerik.Reporting.Drawing.Unit.Cm(4.9999327659606934D)));
            table2.Body.Columns.Add(new Telerik.Reporting.TableBodyColumn(Telerik.Reporting.Drawing.Unit.Cm(4.9999327659606934D)));
            table2.Body.Rows.Add(new Telerik.Reporting.TableBodyRow(Telerik.Reporting.Drawing.Unit.Cm(1.2699999809265137D)));
            table2.Body.SetCellContent(0, 0, txt1);
            table2.Body.SetCellContent(0, 1, txt2);
            table2.Body.SetCellContent(0, 2, txt3);
            Telerik.Reporting.TableGroup tableGroup1 = new Telerik.Reporting.TableGroup();
            Telerik.Reporting.TableGroup tableGroup2 = new Telerik.Reporting.TableGroup();
            Telerik.Reporting.TableGroup tableGroup3 = new Telerik.Reporting.TableGroup();
            Telerik.Reporting.TableGroup tableGroup4 = new Telerik.Reporting.TableGroup();
            tableGroup1.Name = "tableGroup";
            tableGroup1.ReportItem = txtBaslik2;
            tableGroup2.Name = "tableGroup1";
            tableGroup2.ReportItem = txt5;
            tableGroup3.Name = "tableGroup2";
            tableGroup3.ReportItem = txt6;
            table2.ColumnGroups.Add(tableGroup1);
            table2.ColumnGroups.Add(tableGroup2);
            table2.ColumnGroups.Add(tableGroup3);
            table2.Items.AddRange(new Telerik.Reporting.ReportItemBase[] {
            txt1,
            txt2,
            txt3,
            txtBaslik2,
            txt5,
            txt6});
            table2.KeepTogether = false;
            table2.Location = new Telerik.Reporting.Drawing.PointU(Telerik.Reporting.Drawing.Unit.Cm(0.30000147223472595D), Telerik.Reporting.Drawing.Unit.Cm(0.68562471866607666D));
            table2.Name = "table1";
            tableGroup4.Groupings.Add(new Telerik.Reporting.Grouping(null));
            tableGroup4.Name = "detailTableGroup";
            table2.RowGroups.Add(tableGroup4);
            table2.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Cm(14.999796867370606D), Telerik.Reporting.Drawing.Unit.Cm(1.8520833253860474D));
            table2.Style.BorderStyle.Default = Telerik.Reporting.Drawing.BorderType.Solid;
            table2.Style.BorderColor.Default = Color.Black;
            table2.Style.BorderWidth.Default = new Telerik.Reporting.Drawing.Unit(1D, Telerik.Reporting.Drawing.UnitType.Pixel);
            table2.Style.LineStyle = Telerik.Reporting.Drawing.LineStyle.Solid;
            table2.Style.LineColor = Color.Black;
            table2.Style.LineWidth = new Telerik.Reporting.Drawing.Unit(1D, Telerik.Reporting.Drawing.UnitType.Pixel);     

but the table doesnt show , any help please?
0
Hinata
Top achievements
Rank 1
answered on 30 Jan 2014, 05:16 PM
Hello endbil,

I would suggest you to generate a report with a table and test data using the report designer, then look into the code from the Designer.cs file and reuse it. This is the best way to get familiar with the report and Table item structures, so you can control them programmatically.
0
endbil
Top achievements
Rank 1
answered on 31 Jan 2014, 01:11 PM
 hello Hardik

Already, I wrote my code the looking into the code from the Designer.cs file, but the table doesnt show
0
Hinata
Top achievements
Rank 1
answered on 05 Feb 2014, 09:45 AM
Hello endbil

I can't see where you are adding the table item to a report section i.e., something similar to this code:
this.detail.Items.AddRange(new Telerik.Reporting.ReportItemBase[] {this.table2});

Maybe this is the reason why the table is not showing.
Tags
General Discussions
Asked by
Tim
Top achievements
Rank 2
Answers by
Milen
Telerik team
Scott
Top achievements
Rank 2
Steve
Telerik team
Jayesh Goyani
Top achievements
Rank 2
Allen Chan
Top achievements
Rank 1
ott
Top achievements
Rank 1
Jonam
Top achievements
Rank 1
Ibrahim Imam
Top achievements
Rank 1
Daniela
Top achievements
Rank 1
Christopher
Top achievements
Rank 1
Bhanu
Top achievements
Rank 1
Hadib Ahmabi
Top achievements
Rank 1
Randhir
Top achievements
Rank 1
Stef
Telerik team
endbil
Top achievements
Rank 1
Hinata
Top achievements
Rank 1
Share this question
or