How to Dynamically Adjust Table Column Width in Rdlc Report

Dynamic Column width for a RDLC report

Column width is not natively expression based, but you can achieve something like this. Whether it works for you I think will depend on your specific report layout and how the workaround affects any other elements.

Anyway, a simple example. I've created a report against a DataSet with three fields:

enter image description here

I've set val2 to have its visibility controlled by a boolean parameter, HideColumn. This works fine.

Note that there are actually five columns in the table. For val1 and val3 there are actually two columns, and I have merged the fields in the columns together.

The key here is that when HideColumn is set to true, we show the extra columns for val1 and val3, and when it's false we hide the columns - basically the opposite of the visibility for val2.

SSRS will adjust the width of the merged fields accordingly based on which columns are visible:

enter image description here

enter image description here

So in this case it's working as required. For your example you'll need to think about sizing and the required width of these extra columns, but the principle is the same.

This will only work for set columns, i.e. not a matrix, but hopefully will be sufficient for you.

Best way to dynamically create RDLC xml as input to VS2005 Report Viewer?

Lisa Nicholls gives a complete answer in this thread about dynamically defining a report. You'll want to scroll down some before you get to a useful answer. This thread most directly answers your question about controlling which columns are displayed.

These same techniques can be used to size the columns programmatically, but your code will have to figure out the appropriate column widths.

How to keep Reporting services table in the same page

You're using a horizontal table, a great tutorial is described here

You probably have most of the horizontal table figured out, just this part is important to your issue.

Step 4

Right-click on the column header and select "Edit Group". Enter this
for the group expression: =RowNumber(Nothing). This will cause the
matrix to give you one column per row of data. Since horizontal tables
can end up rather wide, you probably want your table wrap around to
the next "line" after a specific number of columns.

Just simply count the number of rows that fit your page exactly and define this number in your column group expression as described in the tutorial.



Related Topics



Leave a reply



Submit