I just want to confirm that to resize the columns on load to fit the max column value size I will need to loop through each value in the column.
I will need to do this for all columns in the grid.
Note I am loading this from a database.
I have tried your sample;
'we'll read the data from a local XML file
'comment this line if you want to access your SQLserver
'uncomment this Fill line if you want to access your SQLserver
Catch ex As Exception
MessageBox.Show("This sample needs to access SQL server. Please recheck the connection string.")
and it seems as though it only resizes based on column title.
Is there a faster way to resize all columns bases on field value?
ADAdministrator 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.