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
close icon

AutoSize Questions

Hi I have two requirements regarding sizing: 1) I'd like to automatically size a column to the width of the widest text cell within that column. I thought I could do this by setting GridStyleInfo.AutoSize = true and WrapText = false, but it doesn't work. Is there a simple way to do this? 2) I have a grid within a popup window. I would like to populate the grid, then autosize the grid and popup window based on the combined width of the grid's columns, such that no scrollbars or whitespace are visible. So the question is, how do I get the width of all the columns? thanks. -dan

3 Replies

AD Administrator Syncfusion Team July 10, 2003 09:34 PM UTC

1) The GridStyleInfo.AutoSize only works as users type into the cell. If you want to programaticcaly size cell, then you should call grid.Model.ColWidths.ResizeToFit, passing in the range you want to size, and various options you might need like IncludeHeaders. 2) To get the total size of all columns, you use grid.Model.ColWidths.GetTotal passing in the start and end column.


JC Jorge Codina July 10, 2003 10:14 PM UTC

> 1) The GridStyleInfo.AutoSize only works as users type into the cell. If you want to programaticcaly size cell, then you should call grid.Model.ColWidths.ResizeToFit, passing in the range you want to size, and various options you might need like IncludeHeaders. > I tried this out and it works beautifully for most cells. But I still have a couple issues: a) On one column that contains only comboboxes (all with the same itemlist) it sizes to about 2 * width of widest text in combobox. This I can work around by simply not autosizing that column. On another column, also with only comboboxes, but shorter text, it works perfectly. This may be a bug in the grid. Sorry I don't have time at present to create a nice test case. b) There seems to a minimum limit beyond which it will not shrink the cell. I have columns with just 2 characters, and the col width remains the default. IE, it is only expanding. I played with all the GridResizeToFitOptions, but no dice. How do I adjust this minimum limit?


AD Administrator Syncfusion Team July 11, 2003 05:56 AM UTC

a) For combobox columns, the grid currenlty resizes based on the ValueMember and not the display member. We will change this behavior in a future release, but currently it is a limitation. This is probably what you are seeing in botn the cases you mentioned. One work-around would be to somehow force the cell to use a representative value while you size. maybe something like this. grid.BeginUpdate(); grid.SuspendChangeEvents(); string s = grid[1, comboCol].Text; grid[1, comboCol].Text = "Some representative value"; grid.Model.Cols.ResizeToFit(myRange, myOptions); grid[1, comboCol].Text = s; grid.ResumeChangeEvent(); grid.EndUpdate(); grid.Refresh(); b) Do you have empty cells? If so, the default sizing behavior is to size empty cells to fit the string "Wg;". If you want empty cells sized to some other string, then set this static (Shared in VB) property of GridCellModelBase. GridCellModelBase.MeasureEmptyCellString = "a";

Loader.
Live Chat Icon For mobile
Up arrow icon