Autosize Columns (Spread 8)

Posted by: imgodot on 8 September 2017, 3:18 pm EST

  • Posted 8 September 2017, 3:18 pm EST

    What is the easiest method to allow Spread columns to autosize based on the data in the header and the data cells AND retain the autosort and autofilter icons?

    I have looked through this forum and read many (old) posts re:
    1) Set wordwrap off, but to do that you have to define the column header cell type yourself.
    2) When you define the column header cell type you lose the autosort and autofilter icons.
    Yes, I saw a post about overriding the Paint event to do it all yourself, but that is just ridiculous.

    In Spread 6, you can easily set wordwrap off and set the grid to autosize all columns and you're done.
    There must be a way to do this in Spread 8 without jumping through a bunch of hoops; isn't there?

    -- Paul
  • Marked as Answer

    Replied 8 September 2017, 3:18 pm EST


    In order to resize the columns on the basis of text present in the columnheader or the cell, you may make us of the 'GetPreferredWidth' method. Using this you can determine the width of the largest data contained in the respective column and then resize the column width accordingly.

    Please refer to the following documentation and the code snippet that you an use to implement the desired behavior :

    Dim value As Double
    value = FpSpread1.Sheets(0).GetPreferredColumnWidth(0)
    Dim col As FarPoint.Win.Spread.Column
    col = FpSpread1.ActiveSheet.Columns(0)
    col.Width = value

Need extra support?

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

Learn More

Forum Channels