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)
if( iCol != myVariableColumn)
iFixed += myGrid.ColWidths[iCol] + 10;
int iVarWidth = myGrid.ClientSize.Width - iFixed;
if( iVarWidth < myVariableMin)
iVarWidth = myVariableMin;
myGrid.ColWidths[myVariableColumn] = iVarWidth;
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?
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.
ADAdministrator Syncfusion Team February 18, 2004 11:24 AM
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.
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.
ABAndy BarnhartFebruary 18, 2004 11:45 AM
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.
ABAndy BarnhartFebruary 18, 2004 05:49 PM
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.