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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Auto-resizing column width after applying grid styles

Thread ID:





72948 Apr 11,2008 02:00 PM UTC Jun 3,2008 09:09 AM UTC WinForms 6
Tags: GridControl
Asked On April 11, 2008 02:00 PM UTC


In the PrepareViewStyleInfo event, I am setting a cell to be bold. This however results in the cell text getting cut-off. I would like to resize the column width, however, I can not call ColWidths.ResizeToFit in the same event (PrepareViewStyleInfo), because I believe that results in the same event being raised again, hence it seems to be running in an infinite loop. Is there a property I can just set which would allow the column to automatically resize?

Thanks in advance.

Replied On April 11, 2008 03:03 PM UTC

Ok there is a bug in ColWidths.ResizeToFit, it does not account for bolded text. I have attached a sample. Basically, it does not resize the column correctly if the text is bolded.



Sri Rajan [Syncfusion]
Replied On April 19, 2008 03:50 AM UTC

Hi Omar,

Thank you for your patience.

Please refer the code below, to resizes the column width and row height when size of the text changes.

Me.gridDataBoundGrid1.Binder.InternalColumns("Col2").StyleInfo.Font.Facename = "Times New Roman"
Me.gridDataBoundGrid1.Binder.InternalColumns("Col2").StyleInfo.Font.Bold = True
Me.gridDataBoundGrid1.Binder.InternalColumns("Col2").StyleInfo.Font.Size = 20


Please let me know if this helps.

Best Regards,

Replied On April 21, 2008 01:31 PM UTC

I'm not using GDBG, I'm using standard GridControl. I believe the bug I'm encountering is the same as was found by somebody else in the 2nd last post in this thread: http://www.syncfusion.com/support/forums/message.aspx?MessageID=38429


Johnson [Syncfusion]
Replied On April 24, 2008 12:15 AM UTC

Hi Omar,

Sorry for the Inconvenience caused.

Normally this issue is occured when you are setting the Font Style in PrepareViewStyleinfo event. PrepareviewStyleInfo event does not store any styleInfo properties in a grid. It just set the visual apperence of the grid. ResizeToFit method resizes a range of rows or columns to optimally fit stored contents of the specified range of cells in grid. It depends on the data stored in a grid. If the Grid doesn't have any data, ResizeToFit method doesn't make any changes in a Grid. Here is a code snippet.

private void gridControl_QueryCellInfo(object sender, Syncfusion.Windows.Forms.Grid.GridQueryCellInfoEventArgs e)
if(font != null)
e.Style.Font = new GridFontInfo(font);

Please let me know if this helps.
Best regards,

Replied On April 24, 2008 06:35 PM UTC

Yes that helps explain the behavior. The grid cell has data stored in it, but the 'bold text' is only being applied in the PrepareViewStyle, so as per your response that is not getting stored and hence accounted for in the ResizeToFit.

Interestingly, I noticed the sample I attached in this thread was overwritten by one I attached in another thread. Both attachments have the same name, if an attachment is not of a unique name it is overwriting the previous attachment.


SubhaSheela R [Syncfusion]
Replied On June 3, 2008 09:09 AM UTC

Hi Omar,

Thanks for your update.

I am afraid that I am not able to find the correct sample. Could you please tell me the exactly your requirement and also send us a minimal sample, so that I will provide you the solution early?

Kindly let me know if you need any further details.

Subhasheela R


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

or the page will be automatically redirected to 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