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:
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:
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
Return Json, But It Includes Backward Slashes "\", Which I Don't Want
Merge Multiple Lists into One List With Linq
Sorting String Values Without Using Any Method/Function
Could Not Start Windows Service, Error 1064
How to Get Column Names of Table At Runtime in C#
How to Get the Am/Pm Value from a Datetime
Choosing the Default Value of an Enum Type Without Having to Change Values
Could Not Parse the Json File ,Error in Progam.Cs ASP.NET Core
How to Generate Database Tables from C# Classes
Filling a Character Array With Characters from a String
How to Call Another Controller Action from a Controller in MVC
Fastest Way to Find Strings in a File
How to Asynchronously Wait for X Seconds and Execute Something Then
How Does Httpcontext.Current.User.Identity.Name Know Which Usernames Exist
Why Am I Getting Error Cs0246: the Type or Namespace Name Could Not Be Found
How to Open the Default Chrome Profile Through Selenium, Chromedriver and Googlechrome