Hi Akamal,
When ResizeToFit method is called with a particular range of cells, Grid calls CellModel.OnQueryPreferredClientSize for all the cells in the range. This method returns the Size for the string. By default grid uses .NET graphics MeasureString method.
//From GridModelBase.cs
///
/// Calculates the preferred size of the cell based on its contents without margins and any buttons.
///
///
The
context of the canvas.
///
The row index.
///
The column index.
///
The
object that holds cell information.
///
///
The optimal size of the cell.
protected virtual Size OnQueryPrefferedClientSize(Graphics g, int rowIndex, int colIndex, GridStyleInfo style, GridQueryBounds queryBounds)
{
return WinFormsUtils.MeasureSampleWString(g, style.GdipFont);
}
///
/// Gets the preferred size to be used for an empty cell.
///
///
The
context of the canvas.
///
The
to be used.
///
The of the string "Wg;".
public static Size MeasureSampleWString(Graphics g, Font font)
{
return g.MeasureString(MeasureEmptyCellString, font).ToSize();
}
You can see MeasureString returns these widths. Here is a CP article discussing about the incorrect width and provides two solutions to get the correct width.
http://www.codeproject.com/cs/media/measurestring.asp
Also refer this Grid KB that uses this approach to get the string width to draw.
http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=24
To get the ResizeToFit to include this width calculation, you need to override the OnQueryPrefferedClientSize and pass in the measured width. Refer to sample for details
Regards,
Madhan.
CharacterDemo_39677.zip