Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
250
Resizing Columns to Fill Grid OR Scrolling?
posted

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?

Parents
No Data
Reply
  • 469350
    Verified Answer
    Offline posted

    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;
            }

Children