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.
Syncfusion Feedback

Resize to fit

Thread ID:





39677 Jan 16,2006 06:44 AM UTC Jan 16,2006 03:03 PM UTC Windows Forms 1
Tags: GridControl
ahmad kamal bin abdul aziz
Asked On January 16, 2006 06:44 AM UTC

Hi guys, I want to put each character in a string into columns in gridControl, then i want the col size (width) fit the charater. so it will look like a string in a column only, currently i''m doing like this: Syncfusion.Windows.Forms.Grid.GridModel gridModel = this.gridControl.Model; gridModel = this.gridControl.Model; gridModel.ColWidths.ResizeToFit (GridRangeInfo.Cells(1, 1, gridModel.RowCount, gridModel.ColCount), GridResizeToFitOptions.None); but col size is still not really fit the col size, there still a white space there, please see an atachment


Administrator [Syncfusion]
Replied On January 16, 2006 03:03 PM UTC

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.



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.

Warning Icon 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.Close Icon