This project is read-only.

How to autosize row height with word wrap?

Apr 12, 2010 at 3:01 PM

Hi!

Is it possible to auto size row height with word wrap? To get exactly same result as in case of double click at the edge of row header. I'm trying:

            grid1.Redim(2, 2);
            
            grid1[0, 0] = new SourceGrid.Cells.Cell();
            grid1[0, 1] = new SourceGrid.Cells.ColumnHeader("C");
            grid1[1, 0] = new SourceGrid.Cells.RowHeader("R");
            grid1[1, 1] = new SourceGrid.Cells.Cell("CONTENT1 CONTENT2 CONTECT3");
            grid1[1, 1].View = new SourceGrid.Cells.Views.Cell()
            {
                WordWrap=true,
            };

            grid1.Columns[1].AutoSizeMode = SourceGrid.AutoSizeMode.None;

after creating it looks like: http://img89.imageshack.us/img89/8353/test1y.png and after AutoSizeCells: http://img691.imageshack.us/img691/1213/test12h.png but I want this (because of word wrap is true): http://img144.imageshack.us/img144/1272/test123.png So, help please to write code to get wanted result?

Nov 8, 2010 at 12:30 PM

Hello,

I'm just evaluating the Grid and would like to do the same with RTF formated cell. Did you find a solution for your problem?

 

With best regards - Ulrich Groffy

Nov 8, 2010 at 5:10 PM

 

"Is it possible to auto size row height with word wrap? To get exactly same result as in case of double click at the edge of row header. I'm trying:"

take a look here

http://sourcegrid.codeplex.com/Thread/View.aspx?ThreadId=233494

i haven't tested with word wrap

May 19, 2011 at 11:18 PM

Yes, it is.  However, I calculate the row height myself rather than using autosize.  When I use autosize I sometimes get an elipse on the last line, but not always.

The calculation to determine the height for a cell is:  

 

SizeF sizeRow = g.MeasureString(grid[row, column].DisplayText, grid[row, column].View.Font, grid.Columns[column].Width - 8);

height = Math.Max(height, (int)Math.Ceiling((Math.Ceiling(sizeRow.Height))));

I then set the row height to the maximum height of the cells in the row.

The View is: 

defaultView = new SourceGrid.Cells.Views.Cell();

 

 

defaefaultView.WordWrap = true;

 

Hope this helps.