Question How to generate CR reports when some fields are unknown?


New member
Sep 27, 2013
Programming Experience
Hi all - I have a question regarding generating reports from a data table using C# in VS.

On a windows form, the user has a datagridview control filled with various accounting items as column headings (rate, credit card, discount, etc.)

Now, there are about a dozen or so columns that are printed every single time, so they are fixed - that's not a problem. However, the user also has the ability to press a button on that form and insert new columns into the datagridview control, and give them names of their choosing. So depending on what they want to display on the form (which is basically an expense spreadsheet), they might have 12 columns, 17 columns, or whatever.

My idea was that once the form was finished and the user had set up the datagridview control to how they wanted it, I'd scan the datagridview control, read out the rows and columns, and create a data table in memory that could then be fed to Crystal Reports to generate printed output, as well as generate PDFs, CSV files etc. that they require.

This is my problem: using Crystal Reports, you need to know in advance what all the fields are, so you can place them on the report template. Obviously you need to know the SQL statement in advance, too. But if the user is creating the columns at run time, I have no way of knowing in advance what the fields are, so the Crystal Report Designer is useless to me. The only thing I can design on the form is the collection of the dozen fixed columns... I have no way of knowing what's going to be additionally required when the application actually runs.

What I want to do is tell the reporting control, "here, go to this data table, read out all of the columns, and just display however many there are in order from left to right. Don't worry about what they mean, just display whatever columns you happen to find when I invoke you."

Is this doable? I've had a quick look around at other report generators, and they all seem to be the same in that you need to open up a report designer, and placed fixed fields at fixed locations. I don't have all of my fields fixed; only some of them.

Can anybody help me out? This is driving me batty.
Top Bottom