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

Words being split when Text wrapping enabled

I have Word Wrapping enabled on my header row. I want the header columns to be taller rather than wider when they contain a lot of text. So first of all I call _grid.RowHeights.ResizeToFit(GridRangeInfo.Row(TitleRow), GridResizeToFitOptions.IncludeHeaders); then I call _grid.ColWidths.ResizeToFit(GridRangeInfo.Cols(0, _grid.ColCount), GridResizeToFitOptions.IncludeHeaders); This mostly works. The only exceptions are columns which contain some long words like "Randomness", "Percentage". These words tend to have the last few letters sent to the next line. Is this a bug, or is there an option I can set to prevent these words from being split and instead have the column made wider. I can''t really do a test on individual columns because the grid is being used generically - the column headers can change each time it''s used. Thanks, Sam

3 Replies

AD Administrator Syncfusion Team March 22, 2004 04:52 AM

One comment is that you are sizing the Colwidths on the whole grid and not just teh header row. (I don''t think this is causing the problem you are having, but just wanted to make sure this is what you want to do.) There is no property setting that will handle this problem. The only way I would know to get this done is to write a method that accepts your header string, and returns a string that has Environment.NewLine''s exactly where you want the breaks to be in the header. Then you could replace the old header text with this new headertext. Then if you call ColWidths.ResizeToFit followed by RowHeightsResizeToFit, I think you would get the behavior you want.


AD Administrator Syncfusion Team March 22, 2004 06:05 AM

>There is no property setting that will handle this problem. The only way I would know to get this done is to write a method that accepts your header string, and returns a string that has Environment.NewLine''s exactly where you want the breaks to be in the header. Then you could replace the old header text with this new headertext. Then if you call ColWidths.ResizeToFit >followed by RowHeightsResizeToFit, I think you would get the behavior you want. > > The problem is not about where new lines are occuring. It is about ResizeToFit on Columns not working correctly: not enough space is being allowed for long words, so that for example when the word "Randomness" should be given enough space to fit on one line, the last "s" is moved onto the next line


AD Administrator Syncfusion Team March 22, 2004 08:03 AM

I understand the problem is the colwidth is not large enough. To get the wrapped text, you have to specify a width. To get the optimal width, you have to know the wrapped text. I think it is a chicken and egg problem. We have not attempted to resolve this problem in our code. We have no algorythm implemented for dynamic wordwrapping with respect for optimal column sizing. To get what you want, I think you will have to call ColWidths.ResizeToFit first. This fixes that column width. Then call RowHeights.ResizeToFit to fix the rowheight based on the column width. To have the absolute narrowest column, I think you will have to go through header text and put hard breaks(Environment.NewLine) in the text. You can do this programatically. This will make calling ColWidths.ResizeToFit size the column width to the size you require. Another option is to derive the cell control and override the CalculatePreferredCellSize in the model. This will allow you to define the ''optimal'' size of your cell. But you would have to handle the dynamic wordwrapping/optimal width problem (which you could do by using the the longest word to define your optimal with as in teh first suggestion. But a general solution probably cannot assume the optimal width should exactly handle the longest word).

Loader.
Live Chat Icon For mobile
Up arrow icon