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

Resize Row for Multi-Line Text Box Entry

Is there a way to automatically resize a row based on the height of a multi-line TextBox in the row?  I have an SfDataGrid with a GridTemplateColumn that contains a multi-line TextBox in the EditTemplate.  I have enabled the Enter key to go through to the text box, but the user can't see what they're typing on the next line because the row does not resize.  A scrollbar appears, but only the top arrow is visible on it.  Thanks for the help.

1 Reply

AS Ayyanar Sasi Kumar Jeyaraj Syncfusion Team November 4, 2015 01:56 PM UTC

Hi Matthew,

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



Loader.
Live Chat Icon For mobile
Up arrow icon