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

AutoSize Questions

Thread ID:

Created:

Updated:

Platform:

Replies:

5621 Jul 10,2003 01:26 PM Jul 11,2003 01:56 AM Windows Forms 3
loading
Tags: GridControl
Jorge Codina
Asked On July 10, 2003 01:26 PM

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

Administrator [Syncfusion]
Replied On July 10, 2003 05:34 PM

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.

Jorge Codina
Replied On July 10, 2003 06:14 PM

> 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?

Administrator [Syncfusion]
Replied On July 11, 2003 01:56 AM

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";

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.

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.

;