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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to set Auto for HeaderRowHeight property?

Thread ID:

Created:

Updated:

Platform:

Replies:

120695 Oct 5,2015 03:13 PM UTC Oct 6,2015 07:00 PM UTC WPF 1
loading
Tags: SfDataGrid
Daniel
Asked On October 5, 2015 03:13 PM UTC

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. 

Sowndaiyan Paulpandi [Syncfusion]
Replied On 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



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

;