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. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Resize column width to fit widest column (html table style)

Thread ID:





6677 Aug 22,2003 05:26 AM UTC Aug 25,2003 09:50 PM UTC WinForms 5
Tags: GridControl
Asked On August 22, 2003 05:26 AM UTC

I am using the virtual grid and I need to handle the size of my columns. My customer would prefer that the table columns is just the size of the widest text in the column. Pretty much like a html table works. Right now I handle the QueryColWidth something like this for the dynamically resized columns: e.Size = longestText.Length * cellFont.Height; Where the longestText is a result of a search for the longest text in the column. Hope you don't mind that all my questions come at once. I have been using the Grid for about three months and I have these final issues before the customer will accept my delivery. Thanks again.

Administrator [Syncfusion]
Replied On August 22, 2003 05:46 AM UTC

Did you mean to type cellFont.Width? Is this not working for you? Another way you can do this is to call grid.ColWidths.ResizeToFit(GridRangeInfo.Table(), GridResizeToFitOptions.None); at some point after you have subscribed to your virtual grid event handlers. Now, if your table is large, this may take some time as it visits each cell dynamically computing the size required using Graphics.MeasureString. So, in that case, your solutiion might be better.

Replied On August 22, 2003 05:57 AM UTC

There is no Width property. It is a proportional font (verdana). The height returns the height of the tallest letter, so multiplying that by the length of a string and hoping to get a good result is a long shot - A hack even. I think I am going to try a MeasureString on the longestText string I have. Good idea. You should consider getting a html mode in some future version. Thanks.

Aaron Ching
Replied On August 23, 2003 08:36 PM UTC

Hi, I have problem with similar issue. I have a GridControl (instead of a DataBound one) and when I double-click on the header border, it shrinks automatically to a fixed width. Is there some properties I need to set in order to have the double-click auto-resize to the width of the max string length? So far, all ResizeToFit samples are referring to a DataBoundGrid. Is there an event on that header-border-double-click so I can call the ResizeToFit from there? Many thanks as usual. Aaron

Administrator [Syncfusion]
Replied On August 24, 2003 08:07 AM UTC

In a GridControl, when you double-click a column border, it resets the row height back to the default size, GridControl.DefaultColWidth. It does not autosize the column. If you want to autosize the column on a doubleclick, you can catch the ResizingCols event, and autosize things yourself. Below is some code.
’ add the handler
AddHandler Me.GridControl1.ResizingColumns, Addressof GridResizingColumns
Private Sub GridResizingCollumns(sender As Object, e As GridResizingColsEventArgs)
	If e.Reason = GridResizeCellsReason.DoubleClick Then
	Me.GridControl1.ColWidths.ResizeToFit( Me.GridControl1.ViewLayout.VisibleCellsRange.IntersectRange(e.Cols), False, True)
		e.Cancel = True
	End If
End Sub ’GridResizingColumns

Aaron Ching
Replied On August 25, 2003 09:50 PM UTC

Thanks very much as always.


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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

Live Chat Icon For mobile
Live Chat Icon