|
#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());
} |