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

RowHeights.ResizeToFit and TextWrapping

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 4.4.0.51 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;


Thanks,
Julie

4 Replies

JL Julie Levy 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).

Thanks,
Julie



wraptext_rowheights.zip


AJ Ajish Syncfusion Team 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.
http://www.syncfusion.com/support/Forums/message.aspx?MessageID=60950

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

Regards,
Ajish


JL Julie Levy 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.

Thanks,
Julie


AJ Ajish Syncfusion Team 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;
grid.Model.RowHeights.ResizeToFit(grid.ViewLayout.VisibleCellsRange);
}

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

Regards,
Ajish.

Loader.
Live Chat Icon For mobile
Up arrow icon