Skip to content

Infragistics Community Forum / Desktop / Ultimate UI for Windows Forms / Resizing Columns to Fill Grid OR Scrolling?

Resizing Columns to Fill Grid OR Scrolling?

New Discussion
Caleb Whitaker
Caleb Whitaker asked on Apr 6, 2017 8:50 AM

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?

Sign In to post a reply

Replies

  • 0
    Mike Saltzman
    Mike Saltzman answered on Jan 27, 2017 5:08 PM

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

    • 0
      Anthony Lisbona
      Anthony Lisbona answered on Apr 6, 2017 8:50 AM

      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?

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Caleb Whitaker
Favorites
0
Replies
2
Created On
Apr 06, 2017
Last Post
9 years, 1 month ago

Suggested Discussions

Tags

Created by

Created on

Apr 6, 2017 8:50 AM

Last activity on

Apr 6, 2017 8:50 AM