2015-07-03

Data Dynamics Reports - Enabling sorting on column headers causes abnormal height growth when CanGrow is True

I ran into a weird one today when working with a Data Dynamics Report (DDR) that needed sorting enabled on the column headers of a table.  Each of the TextBox controls in the column header cells were set to CanGrow=True, which was good to make sure each could fit their content.  Width was forced, so the only way for it to grow was in height.  It worked great until I enabled sorting.

Each column cell required sorting, so I added the SortExpression to each accordingly.  The instant I brought up the report in the WebReportViewer, it looked like the heights of the header cells were twice as tall as needed to fill the largest content of any of the given cells.

I then reverted my changes and the height went back to normal, making the height of the table row equal to the cell with the most content in it.  I deduced that DDR was computing height based on the extra sorting control being added to each cell, but somehow was calculating too much.  As I changed strings, the height would grow relative to the amount of content in the cell... so if the string was longer, the cell would grow all the more tall; looking double what the content in the cell was taking in height.

As I was about to give up and disable sorting on the report because the headers were taking up 1/3 of the page, I decided to try an experiment.

I turned CanGrow=False on every one of the column headers' TextBox controls (leaving the sorting enabled.)  The height went down to minimal, where only one line of text would show, and the rest was hidden because the row wasn't tall enough.  Great.  I have a baseline now!

The next step was to try changing CanGrow=True only on the cell I knew would have the most content in it.
Win!

So if you run into a similar issue, try the following:

  • Change CanGrow=False on all TextBox controls in your column headers, except the cell you know will have the largest content.

No comments: