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
close icon

Auto-resizing column width after applying grid styles

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.


6 Replies

OM Omar 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.

Thanks.



Syncfusion.zip


SR Sri Rajan Syncfusion Team 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

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



Please let me know if this helps.

Best Regards,
Srirajan




OM Omar 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

Thanks.



JO Johnson Syncfusion Team 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,
Johnson




OM Omar 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.

Thanks.



SR SubhaSheela R Syncfusion Team 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.

Regards,
Subhasheela R



Loader.
Live Chat Icon For mobile
Up arrow icon