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

How to set Auto for HeaderRowHeight property?

Hi,

I want to set Auto for HeaderRowHeight property of SfDataGrid.
Some of my headers contain long string and I want to wrap the text (I've written Template for this), but it isn't displayed because height of header row is too small.
I can set HeaderRowHeight property with some value, but I'm not so sure it will look appropriate in different DPI of screens etc. 

1 Reply

SP Sowndaiyan Paulpandi Syncfusion Team October 6, 2015 07:00 PM UTC

Hi Daniel,

Thank you for contacting Syncfusion Support.

We have analyzed your query. You can achieved your requirement to increase the header row height by getting the Formatted text height and set that height to Header row height in Grid loaded event like below code example,

Code Example[C#]:



void
datagrid_Loaded(object sender, RoutedEventArgs e)
        {
            var row = this.datagrid.GetRowGenerator().Items[0];
            FormattedText formattedtext = null;
            var visibleColumns = row.GetType().GetProperty("VisibleColumns", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).GetValue(row, null) as List<DataColumnBase>;
 
            foreach (var item in visibleColumns)
            {
                double maxheight = 0.0;
                string[] columnNames = item.GridColumn.HeaderText.Split(' ');
                foreach (var columnName in columnNames)
                {
                    formattedtext = new FormattedText(columnName,
                                System.Globalization.CultureInfo.CurrentCulture, datagrid.FlowDirection,
                                new Typeface(datagrid.FontFamily, datagrid.FontStyle, FontWeights.Normal,
                                    new FontStretch()), 14, Brushes.Black);
                    maxheight += formattedtext.Height;
                }
                if (datagrid.HeaderRowHeight < maxheight)
                    datagrid.HeaderRowHeight = maxheight;
            }
        }


 


We have prepared a sample based on your requirement and you can download it from the following location.


Sample Location:
http://www.syncfusion.com/downloads/support/forum/120695/ze/WpfSfDataGridHeaderSample822642404

Please let us know if you require further assistance on this.


Regards,
Sowndaiyan



Loader.
Live Chat Icon For mobile
Up arrow icon