Creating dynamic tables

Stimulsoft Reports.NET discussion
Post Reply
User avatar
John
Posts: 132
Joined: Tue Feb 01, 2011 3:56 am
Location: England

Creating dynamic tables

Post by John »

Hallo,

I have been given the task of writing a c# code module which will generate dynamic tables for reports. By dynamic I mean that the number of columns is not known in advance. The consumer of this module of mine will pass a generic DataTable.

So now comes the problem: this table could have, say 10 columns - too many to fit on one page, even rotated to landscape format. Therefore, the code must then say, ok, 5 columns can fit on the page, the other 5 must appear on the next page. (Here, I have just chosen 5 as an example - in fact, the module will probably receive info on the column types and widths and then decide how many will fit on one page).

The resulting table in the report must be collated. That means that page 1 has columns 1-5 and say 20 rows. Page 2 displays columns 6-10 and the first 20 rows, and so on.

I created a sample report in the designer which mimics this setup to a certain extent: two pages - each page has its own table, each table has the same datasource - a DataTable with 10 columns. Table 1 has columns 1-5 and table 2 (on page 2) has columns 6-10. Collation is set for the report to 2.

I then look at the c# code for this report and all the questions appear in my mind:

- This sample report knows it needs 2 pages, 2 tables, each with 5 columns. All of these are hard-coded in the c# code of the report, as are the events which fill each cell from the DataTable.

- How can my module then take the DataTable passed to it, with x columns and y rows and then decide how many pages are required?

- I'd then have to instantiate each page separately, then instantiate a table for it, then add the columns to the table, and then, if possible add an event for each column which just calls one smart event handler. This handler would then know which column and which row is calling it, and would return the correct value from the DataTable.

As you can gather, this is not an easy task. I have searched carefully through the forum and have not yet found anyone who has attempted to implement something like this, although I'd be surprised if I'm the first one.

Do you have any sample code for this? If not, do you have any good tips which would point me in the right direction of how to implement this?

Many thanks,

John Kitching

Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Creating dynamic tables

Post by Alex K. »

Hello,

If we understand you correctly, you want to create a full report of its application.
If you know the data, as well as the width of columns, you can initially calculate necessary number of pages, and then create a report.

Let us know if you need any additional help.
Thank you.
Post Reply