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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Resize Row for Multi-Line Text Box Entry

Thread ID:

Created:

Updated:

Platform:

Replies:

121023 Nov 3,2015 05:45 PM UTC Nov 4,2015 01:56 PM UTC WPF 1
loading
Tags: SfDataGrid
Matthew Snyder
Asked On November 3, 2015 05:45 PM UTC

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.

Ayyanar Sasi Kumar Jeyaraj [Syncfusion]
Replied On 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



CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;