Hi,
I'm using autosize to resize the columns in my grids, works fine except for highlighted (selected) columns where the font changes to bold for example.. this as expected cut's off the end of the text. A minor point but is there a way to get the autosize to compensate for this?
Thanks
How are you applying the bold font to the selected cells?
The AutoSizing functionality probably doesn't take into account the font settings on each individual cell in the column, because if it did, it would cause a pretty big performance hit. So the autosizing is probably done based on the resolved font of all the cells in the column without accounting for any font changes on individual cells.
It's set in the AppStyle for the project on project start up, I'm not changing it after it's loaded. The style is taken from one of the included templates. I suppose the easy answer is to change this but is it something you could consider as a bug fix...
Hm. So just so I'm clear here, you have an application style which makes the selected cells in the grid bold. And you are selecting a column in the grid (which makes all the text in the column bold) and then calling PerformAutoResize on this column in code. And it's not sizing wide enough to account for the bold text. But when you de-select the column and it is no longer bold, the size is correct and the text fits?
I'm not sure the current behavior is wrong. You are expecting the autosize to account for a transitory and temporary state. If it did so, then when the column was de-selected, it would be too wide and use up extra space unneccessarily.
Suppose it were reversed and you have a bold font when the column was not selected and not bold when it was selected. I grant you, that would probably be a less common case, but in such a case, the autosize would size the selected column to the non-bold text and then when the column was unselected, it would end up being too small.
I could be wrong, but my guess is that the grid intentionally strips out any state-specific appearance information like theselected state when calculating the auto-sizing of the cell.
I'd probably avoid changing fonts based on transitory states, myself. You will likely have problems with other controls besides the grid.
But, if you want to work around this, what you could do is use the CalculateAutoResizeWidth method of the column, instead of PerformAutoResize. Then you could add some extra padding to the value if the column is selected. Of course, this would not be truly accurate, you'd have to guess at the amount of padding.