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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Auto sizing columns

Thread ID:





10969 Feb 18,2004 01:45 PM UTC Feb 18,2004 10:49 PM UTC WinForms 4
Tags: GridControl
Andy Barnhart
Asked On February 18, 2004 01:45 PM UTC

I have been trying to autosize my columns based on internal settings for fixed and variable width columns. My variable width column also does text wrapping, so the Autosize property doesn''t help me (or so it seems to me). If I understand correctly, the autosizing done by the grid itself only can be width or height but not both. If I am correct, I think that is a mistake. I have a column that may contain a lot of text, so I want it to take up as much width as is available and then autosize the height based on how much text wrapped. Anyway, I am attempting to do it myself and my calculations are off a little bit. If I do this: public void CheckColSizes() { int iCol = myGrid.ColCount; int iFixed = 0; while (iCol > 0) { iCol--; if( !myGrid.HideCols[iCol]) { if( iCol != myVariableColumn) { iFixed += myGrid.ColWidths[iCol] + 10; } } } int iVarWidth = myGrid.ClientSize.Width - iFixed; if( iVarWidth < myVariableMin) iVarWidth = myVariableMin; myGrid.ColWidths[myVariableColumn] = iVarWidth; myGrid.RowHeights.ResizeToFit(Syncfusion.Windows.Forms.Grid.GridRangeInfo.Table()); } I end up with the last column partially out of the window. I thought it had to do with the scroll bar at first, but it doesn''t (same problem if there is no vertical scroll bar). It would seem that I need to add borders or what not. How can I correct this? -Andy

Andy Barnhart
Replied On February 18, 2004 01:47 PM UTC

oops, I left the " + 10" in there while I was just fooling around testing to see if it was fixed in my particular grid. It is not. 10 works for 4 columns, but not for other numbers of columns. I wasn''t plannig to use a literal number; just checking to see if it was a literal number.

Administrator [Syncfusion]
Replied On February 18, 2004 04:24 PM UTC

Here is a little sample using your idea. Size the form before clicking the button to see it work to fill us the new client region of the grid. forum10969_1800.zip The only tricky part is that calling RowHeights.ResizeToFit has the potential to make the vertical scrollbar appear if it is not already visible since increasing the hieght of the cells may mak eit so not all rows are visible. So, to handle this, one option is to just always make it visible to avoid this problem.

Andy Barnhart
Replied On February 18, 2004 04:45 PM UTC

I got that to work with a couple of minor alterations. If the row headers are not shown, it still includes them in the calculation, so it wasn''t filling the window. I had to change the 0 to a 1 in the calculation of usedWidth to the left. That worked. It works okay with other columns being hidden though. The other thing I do is call my function to check the row sizes in response to scroll bar visibility changing as well as resize. -Andy

Andy Barnhart
Replied On February 18, 2004 10:49 PM UTC

Just wanted to make sure you realized there was a bug report (I think) in that last message. I mean the bit about the row headers (AKA column 0) being included in the width even if they aren''t shown. Hopefully, that can be fixed before 2.0 is released.


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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

Live Chat Icon For mobile
Live Chat Icon