Resize Row for Multi-Line Text Box Entry
Thank you for contacting Syncfusion support.
We have analyzed your query.
You can automatically resize a row when you type multi-line text in SfDataGrid by using QueryRowHeight event.
C#:QueryRowHeightEvent
|
private void datagrid_QueryRowHeight(object sender, QueryRowHeightEventArgs e) { if (this.datagrid.GridColumnSizer.GetAutoRowHeight(e.RowIndex, gridRowResizingOptions, out Height)) {
e.Height = Height;
e.Handled = true;
}
|
For measuring the text while using GridTemplateColumn, you need to derive a new class from our GridColumnSizer and override the MeasureTemplate method like below,
C#:GridColumnSizer.
|
public class dColumnSizerExt : GridColumnSizer { public dColumnSizerExt(SfDataGrid grid) : base(grid) {
} protected override Size MeasureTemplate(object record, GridColumn column) { var data = record.GetType().GetProperty(column.MappingName).GetValue(record); var datatext=Convert.ToString(data); FormattedText formattedtext = GetFormattedText(column, record, datatext); formattedtext.Trimming = TextTrimming.None; formattedtext.MaxTextWidth = this.DataGrid.GetVisualContainer().ColumnWidths.DefaultLineSize; formattedtext.MaxTextHeight = double.MaxValue; if (formattedtext.MaxTextWidth > (Margin.Left + Margin.Right)) formattedtext.MaxTextWidth -= (Margin.Left + Margin.Right); return new Size(formattedtext.Width, formattedtext.Height); }
private FormattedText GetFormattedText(GridColumn column, object record, string datatext) { FormattedText formattedtext; formattedtext = new FormattedText(datatext, System.Globalization.CultureInfo.CurrentCulture, DataGrid.FlowDirection, new Typeface(FontFamily, new FontStyle(), new FontWeight(), new FontStretch()), 14, Brushes.Black); return formattedtext;
|
We have also prepared the sample based on this and you can download the sample from the below location,
Sample:
http://www.syncfusion.com/downloads/support/forum/121023/ze/forumrowdatahidden_-_Copy-1200590883
Please let us know if you have any further assistance
Regards
Ayyanar
- 1 Reply
- 2 Participants
-
MS Matthew Snyder
- Nov 3, 2015 05:45 PM UTC
- Nov 4, 2015 01:56 PM UTC