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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

resize window form to best fit the grid

Thread ID:

Created:

Updated:

Platform:

Replies:

28652 May 6,2005 01:38 AM UTC May 6,2005 10:12 AM UTC WinForms 3
loading
Tags: GridControl
Eric Luk
Asked On May 6, 2005 01:38 AM UTC

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

Administrator [Syncfusion]
Replied On 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);

Eric Luk
Replied On 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

Administrator [Syncfusion]
Replied On 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\3.2.1.0\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.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;