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

RowHeights.ResizeToFit and TextWrapping

Thread ID:





67613 Aug 24,2007 05:37 PM UTC Aug 30,2007 11:54 PM UTC WinForms 4
Tags: GridControl
Julie Levy
Asked On August 24, 2007 05:37 PM UTC

Hi -
When trying to get the gridcontrol to load with wrapped text columns i found that the wrapping would not occur unless i called RowHeights.ResizeToFit() on the entire grid after the data was all loaded. However, this causes the overall loading to be slow.

Is this how wrapping is supposed to work or is there a way for the wrapping to occur as you build the row without having to call resize?

I am using version and am copying data into the grid cell by cell (building one row at a time) using the following code (not a virtual grid):

GridStyleInfo cellStyle = new GridStyleInfo();
cellStyle.Trimming = StringTrimming.EllipsisWord;
cellStyle.CellType = CELLTYPE_STATIC;
cellStyle.CellValue = text;
cellStyle.CellValueType = cellType;
cellStyle.HorizontalAlignment = hAlign;
cellStyle.VerticalAlignment = vAlign;
cellStyle.WrapText = this.AllowTextWrap ? wrapText : false;
cellStyle.ReadOnly = true;
this.Data[rowIndex, colIndex] = cellStyle.Store;


Julie Levy
Replied On August 24, 2007 06:18 PM UTC

I also call RowHeights.ResizeToFit in the ResizingColumns event and get the attached strange behavior as i resize the column with the mouse. Sometimes the wrap only works on some rows and not others (text is truncated) even though the range i use is the same (all rows).



Ajish [Syncfusion]
Replied On August 25, 2007 12:37 AM UTC

Hi Julie,

Thank you for your patience.

Please refer to the following forum thread which discusses about the performance related with ResizeToFit method.

Kindly refer to it and let us know if you need any further assistance.


Julie Levy
Replied On August 27, 2007 09:43 PM UTC

Hi -
thanks for you reponse. So are you saying the following:
1. Resizing is required after loading in order to get text to wrap
2. The only way to speed up resize is to do it manually and inspect each cell to see if it needs to be resized before resizing? This is faster?

Is this the recommended approach for wrapping text? That's all i'm trying to accomplish with the resize.

Note that i am using a grid control (not databound) and have no hidden rows.


Ajish [Syncfusion]
Replied On August 30, 2007 11:54 PM UTC

Hi Julie,

Yes, as discussed in forum thread # 60950. The reason is that the ResizeToFit method will visit every cell in the range, and call MeasureString method to calculate the size of the cell. This will take time for large number of rows. But right now, You can speed up the process to limit the number of cells that you check. One simple way is to only resize the visible rows.

Another way would be to use something other than visiting each cell and calling MeasureString method. For example, if a column is a numeric value you could ’approximate’ the widest the cell could be by multiplying the max digits times the average character width for the font. This would just be a quick calculation without having to visit every cell. Or, if you know the maximum number of characters in a field of your database, you could set its width based on the max number of characters and the average character width. So, instead of calling ResizeToFit (and having it visit every cell), you would just call some calculation that would approximate the needed width.

In GridControl, you can handle the TopRowChanged event and resize it accordingly.
this.gridControl1.TopRowChanged += new GridRowColIndexChangedEventHandler(gridControl1_TopRowChanged);

void gridControl1_TopRowChanged(object sender, GridRowColIndexChangedEventArgs e)
GridControl grid = sender as GridControl;

Kindly take a look and me know if you any other questions.



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