Report with variable number of columns

Stimulsoft Reports.NET discussion
Post Reply
simongb
Posts: 3
Joined: Fri Aug 02, 2019 3:29 pm

Report with variable number of columns

Post by simongb »

Hi,

As the title say, I'm trying to create a report which could contain pretty much any number of columns...
I would allow the user to decide which columns they want in their report. The subset of columns chosen by users will usually be 6-7, but could theoretically be much more.
Fitting in a page for printing would be nice, but isn't that important since most users will export reports to Excel.

Before I've "solved" this problem by adding lots of columns, like this:
Capture.PNG
Capture.PNG (11.02 KiB) Viewed 1713 times
and hiding the columns the user does not want to have in their report.

It wouldn't really work in this case, though, since users couldn't add any number of columns...

Any help/references on how to fix this problem would be greatly appreciated!
Lech Kulikowski
Posts: 6245
Joined: Tue Mar 20, 2018 5:34 am

Re: Report with variable number of columns

Post by Lech Kulikowski »

Hello,

You can use Conditions with "Component Is Enabled" option.
Please check the sample report in the attachment.

Thank you.
Attachments
SelectingColumns_Variables.mrt
(813.15 KiB) Downloaded 136 times
simongb
Posts: 3
Joined: Fri Aug 02, 2019 3:29 pm

Re: Report with variable number of columns

Post by simongb »

Hello,

Thank you for you response. Unfortunately, I don't think this would work for me. I don't want to only hide columns the users do not want to see... I want users to be able to add any number of columns they want.
If I use your sample, it would be like if users could add custom properties to products. Some properties such as ProductID, ProductName, SupplierID, etc. would always be there. But users could add some custom properties. For example:
Client #1 could add custom properties like "Comments", "Rating". Client #2 could add the properties "Notes" and "Details".
It's impossible for me to add those columns in the MRT, because I have no idea what they are, and they can change from one client to the other. (e.g Client #1 might want ProductID, ProductName and Comments while Client #2 needs ProductID, ProductName, SupplierID, Comments and Rating.)
Lech Kulikowski
Posts: 6245
Joined: Tue Mar 20, 2018 5:34 am

Re: Report with variable number of columns

Post by Lech Kulikowski »

Hello,

In that case, these columns should be in the dictionary, you should add it in your data source and provide it to the report.

Thank you.
simongb
Posts: 3
Joined: Fri Aug 02, 2019 3:29 pm

Re: Report with variable number of columns

Post by simongb »

How do I do that programmatically? I see how to add columns in the MRT file, but not how to add them dynamically in the code. I want to be able to display any number of columns, that can have any names,all decided by the user at run time in my application.
Lech Kulikowski
Posts: 6245
Joined: Tue Mar 20, 2018 5:34 am

Re: Report with variable number of columns

Post by Lech Kulikowski »

Hello,

You can add necessary columns in the DataTable and the provide it to the report with RegData() method.

Thank you.
Post Reply