We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

resize window form to best fit the grid

Hi, I would like to resize my form size according to the size of the grid inside so that my form can be of size just big enough to show all the cells on the grid, but not less or more than that (i.e. no blank grid area shown). I can''t find any properties on the grid that can do it. Do you have any recommandation on it? Thanks a lot! Eric

3 Replies

AD Administrator Syncfusion Team May 6, 2005 08:12 AM UTC

You can get the width and height you need using ColWidths.GetTotal and RowHeights.GetTotal. Then you would need to set the grid''s client size to be this width and height. If you want to do this using a form, then exactly how you would do this depend upon how you are anchoring /docking the grid in the form. Here are some snippets for the grid being dock-filled in the form. grid.Dock = DockStyle.Fill; int width = grid.Model.ColWidths.GetTotal(0, grid.Model.ColCount); int height = grid.Model.RowHeights.GetTotal(0, grid.Model.RowCount); //not needed because dockfill - need to set the parent''s clientsize //grid.ClientSize = new Size(width, height); this.ClientSize = new Size(width, height);

EL Eric Luk May 6, 2005 09:29 AM UTC

Hi Clay, Thx a lot! It works, except that when I resize the form (with a grid and a toolbar at the top) to best fit, there will be a horizontal scrollbar shown at the bottom, this is what I don''t want to have. I have ugly hack it on my own using the Size() method by resizing it to a bit larger and then resize to best fit. This can kick away that unnecessary scrollbars. Thanks a lot! Eric

AD Administrator Syncfusion Team May 6, 2005 10:12 AM UTC

I suspect this really is dependent upon how you have your grid docked/achored in the form in relation to how the form is sized. If you size the form such that there is not sufficient width to hold the grid''s columns, then the grid will show a scrollbar. If you can upload a sample showing the problem, maybe we can suggest a solution. Do you want the columns to change widths (become smaller) to avoid this? If so, you can handle grid.Model.QueryColWidth to dynamically set the colwidths to be 1 /(number of columns) times the grid''s clientwidth. You can see a sample of this in Syncfusion\Essential Studio\\Windows\Grid.Windows\Samples\DataBound\GridDataBoundImageCell. If all you want to do is make sure teh grid does not show a horizontal scrollbar, you can turn it off by setting the grid.HScrollbarBehavior to Disabled.

Live Chat Icon For mobile
Up arrow icon