Show the complete RichText

I want to create an application to generate invoices. The user should enter text in a cell (RichText). The width of the column is fixed.
The height of the row should automatically adjust as the user saves the text. The entire text should always be visible.

How can I realize that?

Thanks in advance
George


1 Reply

AR Arulpriya Ramalingam Syncfusion Team November 6, 2017 07:17 PM UTC

Hi George, 

Thanks for using Syncfusion products. 

As per our grid current support, the RichTextBox cell does not have the support to edit the cell value in the cell itself and moreover, the row height could not be resized based on text length. The content for the RichText cell will be edited in the dropdown and added to cell as rtf text. In order to resize the row height as your scenario, customRichTextCellModel can be created by implementing the GridRichTextBoxCellModel and the OnQueryPrefferedClientSize() method can be overridden to resize the cell based on text length. Please refer to the below code and sample, 

Code snippet: 
 
#region CustomRichTextCell 
public class CustomRichTextCell : GridRichTextBoxCellModel 
{ 
    public CustomRichTextCell(GridModel grid):base(grid) 
    { 
        this.ButtonBarSize = new Size(15, 15); 
    } 
    protected override Size OnQueryPrefferedClientSize(Graphics g, int rowIndex, int colIndex, GridStyleInfo style, GridQueryBounds queryBounds) 
    { 
        string sOutput = String.Empty; 
 
        try 
        { 
            sOutput = this.GetFormattedOrActiveTextAt(rowIndex, colIndex, style); 
        } 
//Some code 
        else 
        { 
           //To measure the height for the rich text cell based on cell value 
           textSize.Height = (int)g.MeasureString(sOutput, font, textSize.Width, format).Height; 
        } 
    } 
//Some code 
        return textSize; 
} 
#endregion 
 
//adding custom rich text cell to the grid 
this.gridControl1.CellModels["RichTextCell"] = new CustomRichTextCell(this.gridControl1.Model); 
this.gridControl1.ColStyles[3].CellType = "RichTextCell"; 
this.gridControl1.ColStyles[3].CellValue = "This is the RichTectboxCell which resizes the height based on text"; 
this.gridControl1.RowHeights.ResizeToFit(GridRangeInfo.Table()); 
//Event Triggering 
this.gridControl1.CurrentCellCloseDropDown += GridControl1_CurrentCellCloseDropDown; 
//EVent Customization 
private void GridControl1_CurrentCellCloseDropDown(object sender, PopupClosedEventArgs e) 
{ 
    //To udate the cell value 
    this.gridControl1.CurrentCell.EndEdit(); 
    //To resize the rich text box cell when dropdown is closed 
    this.gridControl1.RowHeights.ResizeToFit(GridRangeInfo.Table()); 
} 
 
 
Note 
The WrapText and AutoSize property should be set to true to resize the row height automatically. 

Arulpriya 


Loader.
Up arrow icon