AD
Administrator
Syncfusion Team
November 19, 2002 11:06 AM
Unless you have special knowledge of the contents of a column, then you will have to use code that somehow looks at each cell to size the cell.
For example, if you know a column can only have a 5 digit integer, then you can just explicitly set the column width to 5 * average character width for the font you are using. This is what I mean by special knowledge of the column contents.
The ColWidths.ResizeToFit method uses the range that is passed in to decide what cells it will use to size the colwidths. So, in the code you listed, it uses GridRangeInfo.Row(0), which is row 0, or the column header row. That is why that code sizes the cells only based on the column header. If you pass it GridRangeInfo.Table, then it will size things based on the whole table. If you pass it, GridRangeInfo.Cols(2), itr will size column 2, and so on.
So, if your table is not too large, calling Colwidths.ResizeToFit passing the whole table may be reasonable. But if your table is huge, this may not be an option. In that case, you could try just resizing the visible portion by restricting the range between the grid.TopRowIndex and the grid.ViewLayout.LastVisibleRow. Or, you could use special knowledge to size things without having to look at the contents of every cell.