Posted by: dagana on 8 September 2017, 2:15 pm EST

  • Posted 8 September 2017, 2:15 pm EST

    Hi Expert,

    I try to AutoFit column of my spread sheet. Data are coming from a dataset. Column Header are larger than column content. Example: Column Header "Available Stock" Column content: 100. When I used GetPreferredColumnWidth(ColIndex) or GetPreferredColumnWidth(ColIndex, true) or GetPreferredColumnWidth(ColIndex, false).... I always have the same result: Autofit is done only on the data and my Column Header is to short.

     What I am not doing correctly?


  • Replied 8 September 2017, 2:15 pm EST

    Hello Dagana,

    By default, WordWrap is turned on in the headers and the GetPreferredColumnWidth() will not size any larger text in headers, since the text is wrapped. So, you need to turn off the WordWrap in the header.


     FarPoint.Win.Spread.CellType.EnhancedColumnHeaderRenderer ecr = new FarPoint.Win.Spread.CellType.EnhancedColumnHeaderRenderer();
     ecr.WordWrap = false;
     fpSpread1.Sheets[0].ColumnHeader.DefaultStyle.Renderer = ecr;
     fpSpread1.ActiveSheet.GetPreferredColumnWidth(3, false);


    Hope it will help you. Thanks

  • Replied 8 September 2017, 2:15 pm EST

    Hi Reeva,

     Thank you very much for your help. My column width is now adjust automatically perfectly.

     Now, I tried to adjust my header height automatically with GetPreferredHeight but I guess I do something wrong because it's not working. This is the function I use

    <FONT size=2>s.ColumnHeader.Rows[0].Height = s.ColumnHeader.Rows[0].GetPreferredHeight();</FONT>

    <FONT size=2>Example: column header: Sales Avg \n Last 13 \n Weeks</FONT>

    <FONT size=2>It's now set like everything was on 1 line.</FONT>

    <FONT size=2></FONT> 

    <FONT size=2>Thanks,</FONT>

    <FONT size=2>Dagana

    </FONT><FONT color=#008000 size=2><FONT color=#008000 size=2></FONT></FONT>
  • Replied 8 September 2017, 2:15 pm EST

    Hello Dagana,

    We are unable to replicate the issue stated by you with Spread's version 4.0.3515.2008 as on setting the column header text having new line characters and using the GetPreferredHeight() to set the height of the ColumnHeader we are getting the text in 3 different lines.

    Please find attached image for the same. And also let us know the version of Spread you are using?


Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels