Can anyone help me how to auto size the colums when the grid is loaded initially.
Thanks.
Hi,
What I usually do is use the InitializeLayout event of the grid. Use e.Layout.Bands and loop throughthe bands collection. On each band, loop through the columns and call the PerformAutoResize method. Be sure to pass in AllRowsInBand to PerformAutoResize - otherwise it will only autosize on the loaded rows and there won't be any at that point.
Thanks for the reply.
The columns are resized properly but the column headers are adjusted to the column size too. Is there any property to make the headers visible with PerformAutoResize property.
Thanks for the help.
I know of no easy way to do this. You would have to use MeasureString to measure the size of the band header text yourself to determine the minimum width. Then AutoSize the columns. And then see if there is any extra space, and if so, decide where to distribute it amongst the columns.
Another (simpler) option might be to apply a MinWidth to each column up front to ensure that there is always enough space.
Hi Mike,
how do I do an autosize that also takes the UltraGridBand.Header.Caption's size into account?
e.g. if the band header has a long caption, but the columns have a short caption, I would like the autosize to still show the whole header caption.
Thanks!
PerformAutoResize always accounts for the column header. If you want to ignore the column header, you can use the CalculateAutoResizeWidth method on the column. This method allows you to specify whether or not to include the header and returns the width that the column should be. So then you just set teh column.Width to the returned width.
PerformAutoResize was called after set Caption property, the problem above has been fixed.
Another problem:
I want to antosize some column according content(Not caption), how to implement that?
Many thanks,
Alfonzoe
Hi Alfonzoe,
I beleive the issue above is that the Caption property on the column was being set after the PerformAutoResize was called. So the column was sized based on the original caption, then the caption was changed, so the column could not account for the size of the caption text. Are you changing the column captions or the data in the grid after InitializeLayout has fired?