I have a Grid which is used for many different sets of data. Sometimes there's only a few columns other times there are many.
I won't the columns to resize to their content AND fill the Grid IF they don't already fill the Grid.
So if the content is large enough that the Columns are wider than the Grid I want a scroll bar but if not I want them to be resized.
I know how to resize them based on content with PerformAutoResize and how to use AutoFitStyle.ResizeAllColumns but not how to use both together. So when the columns stretch wider than the Grid they end up being compressed to fit to the Grid when I want them to stay how they are.
Any ideas? Is there a way to check if the columns are wider than the grid after the autoresize so that I can set AutoFitStyle.None in that case?
Hi Mike
In tried you approach suggested above, but when my grid is loaded, it is not auto sizing the columns; some have a lot of white space (red arrows in screenshot), while others have their contents cut off (blue arrows), and the horizontal scroll bar is disabled?
What am i doing wrong?
Hi Caleb,
Well... it seems to me like what you really want here is to AutoFit the columns, but also make sure that the column's minimum width doesn't fall below the width necessary to fit the contents.
When you think about it like that, I think it should be pretty simple. What you do is AutoSize each column and then set the MinWidth on that column to the calculated auto-size. Then when you set AutoFitStyle, that setting resize the columns bigger if it can, but it will not be able to make the columns smaller than the minimum and so you will get a scrollbar when needed.
I tried it out in a simple sample and it seems to work.
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { var layout = e.Layout; var band = layout.Bands[0]; foreach (var column in band.Columns) { column.PerformAutoResize(PerformAutoSizeType.AllRowsInBand, AutoResizeColumnWidthOptions.All); column.MinWidth = column.Width; } layout.AutoFitStyle = AutoFitStyle.ResizeAllColumns; }
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { var layout = e.Layout; var band = layout.Bands[0];
foreach (var column in band.Columns) { column.PerformAutoResize(PerformAutoSizeType.AllRowsInBand, AutoResizeColumnWidthOptions.All); column.MinWidth = column.Width; }
layout.AutoFitStyle = AutoFitStyle.ResizeAllColumns; }