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.
Yes..I called Caption first and then PerformAutoResize(). That fixed it.
Hi Cbvidya,
I also meet the same problem you talked above, and eager to know the solution, could post the detailed answer?
I don't know what the meaning of "called Caption first and then PerformAutoResize(). ".
I have tried using the following, but it doesn't works:
private void ugListing_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { foreach (UltraGridBand band in e.Layout.Bands) {
for (int count = band.Columns.Count - 1; count >= 0 ; count--) { band.Columns[count].PerformAutoResize(PerformAutoSizeType.AllRowsInBand); } } }
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?
Hi Mike,
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,
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.
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.
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!