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.

Auto-resizing column width after applying grid styles

Thread ID:

Created:

Updated:

Platform:

Replies:

72948 Apr 11,2008 10:00 AM Jun 3,2008 05:09 AM Windows Forms 6
loading
Tags: GridControl
Omar
Asked On April 11, 2008 10:00 AM

Hi,

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.


Omar
Replied On April 11, 2008 11:03 AM

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.

Thanks.



Syncfusion.zip

Sri Rajan [Syncfusion]
Replied On April 18, 2008 11:50 PM

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

Me.gridDataBoundGrid1.Model.ColWidths.ResizeToFit(GridRangeInfo.Table())
Me.gridDataBoundGrid1.Model.RowHeights.ResizeToFit(GridRangeInfo.Table())



Please let me know if this helps.

Best Regards,
Srirajan



Omar
Replied On April 21, 2008 09:31 AM

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

Thanks.


Johnson [Syncfusion]
Replied On April 23, 2008 08:15 PM

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,
Johnson



Omar
Replied On April 24, 2008 02:35 PM

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.

Thanks.


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

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.

Regards,
Subhasheela R



CONFIRMATION

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.

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.

;