13

Lets say that I have 10 columns to view report and I want to hide 3 of these columns at runtime based on the value of parameter which the user would select. This can be easily done by setting the column visibility of each of these 3 columns based on the value of the aforesaid parameter. It's perfectly fine up till here.

The problem is when the report shows up (with 3 columns hidden) the remaining 7 columns take up the place of the hidden columns and as a result the overall width of the table reduces accordingly. I do not want this to happen. i.e. I want the table width to remain constant.

That is to say the remaining columns width should somehow be able to expand so that the original overall width of the table remains same.

Is this possible to achieve?

Vinayak Garg
  • 6,518
  • 10
  • 53
  • 80
Shohel
  • 3,886
  • 4
  • 38
  • 75

2 Answers2

22

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.

Ian Preston
  • 38,816
  • 8
  • 95
  • 92
  • Hi Ian Preston,I am trying to do this for a long. Do you have sample of codes/reports for this? – Shohel Apr 29 '13 at 04:22
  • 3
    I'm sorry, but I don't know what you mean when "for a long". Can you please provide more information? – Ian Preston Apr 29 '13 at 08:08
  • For a long means,Many time have been passed,please send me code or another way,your example does not work. – Shohel Apr 29 '13 at 09:31
  • 2
    What do you mean does not work? You need to be more specific. You can see above that it works for me - I even shown the exact steps I used to create the sample report. Is it that you don't think this will work for your report? That you've tried to get it working but couldn't? You need to give more detail about what you've tried and the specific issues you had - I can't write the report for you. I suggest trying to create a simple report as above to get familiar with the process. – Ian Preston Apr 29 '13 at 13:00
  • I have 25 columns and 15 columns may be hide or show it is dificult to mange 15 columns hide or show and column width change proportinally,Please send me another way so that i can easily to solve this.Thanks and Regards. – Shohel Apr 30 '13 at 02:42
  • I dont know if my message will find u after about 3 years later but I am trying your solution here and I have a problem that when I am setting the visibility of extra columns to "hidden:true" they are making all the table's visibility to "hidden:true" :( I am using SSRS 2010. Any advice? – Eray Balkanli Feb 26 '16 at 16:04
0

I could not find a solution that is natively supported by Reports, nor did I find a solution online that was satisfying. So I wrote some code to manipulate the XML before using it in the reportview. It redistributes the width of hidden columns:

https://github.com/DaveyvanTilburg/RDLCDynamicColumns

Example piece of the xml being altered (can find the full example in github)

The before:

<TablixColumn>
    <Width>4.20cm</Width>
</TablixColumn>
<TablixColumn>
    <Width>12.4567cm</Width>
</TablixColumn>
<TablixColumn>
    <Width>10.50cm</Width>
</TablixColumn>

The after, where the 2nd column will be hidden, and its width is redistributed over the visible columns:

<TablixColumn>
    <Width>10.428350cm</Width>
</TablixColumn>
<TablixColumn>
    <Width>0cm</Width>
</TablixColumn>
<TablixColumn>
    <Width>16.728350cm</Width>
</TablixColumn>