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.

RowHeights.ResizeToFit and TextWrapping

Thread ID:

Created:

Updated:

Platform:

Replies:

67613 Aug 24,2007 01:37 PM Aug 30,2007 07:54 PM Windows Forms 4
loading
Tags: GridControl
Julie Levy
Asked On August 24, 2007 01:37 PM

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

Julie Levy
Replied On August 24, 2007 02:18 PM

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

Ajish [Syncfusion]
Replied On August 24, 2007 08:37 PM

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

Julie Levy
Replied On August 27, 2007 05:43 PM

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

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

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.

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.

;