a .NET equivalent for Spread.ColWidth(0) = Spread.MaxTextColWidth(0)

Posted by: bdota on 8 September 2017, 2:25 pm EST

  • Posted 8 September 2017, 2:25 pm EST


    In VB 6.0 I could write  Spread.ColWidth(0) = Spread.MaxTextColWidth(0)

    what is the .NET equivalent for this ? ( Farpoint v5.0) 



  • Replied 8 September 2017, 2:25 pm EST

    thanks for the <span class="Apple-style-span" style="font-family:Tahoma, Arial, Helvetica;font-size:17px;">GetPreferredColumnWidth  but in VB 6.0 version when we pass zero it means "row headers"</span>

    but in the .NET version when we pass zero it means the first column, not the row headers  or maybe i am wrong 

  • Replied 8 September 2017, 2:25 pm EST


    You need to first turn the word wrap off for Row Header and set the RowHeader Column width using


    Below is an example to achieve the same:

    <span class="Apple-style-span" style="border-collapse:separate;font-family:Tahoma;font-size:16px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;orphans:2;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;"><span class="Apple-style-span" style="font-family:'Courier New';font-size:12px;text-align:left;">FarPoint.Win.Spread.CellType.GeneralCellType g = new FarPoint.Win.Spread.CellType.GeneralCellType();<span class="Apple-converted-space"> </span>
    g.WordWrap = false;<span class="Apple-converted-space"> </span>
    fpSpread1.ActiveSheet.RowHeader.Columns[0].CellType = g;<span class="Apple-converted-space"> </span>
    fpSpread1.ActiveSheet.RowHeader.Cells[0, 0].Text = "This is a test string";<span class="Apple-converted-space"> </span>
    float s = fpSpread1.ActiveSheet.RowHeader.Columns[0].GetPreferredWidth;<span class="Apple-converted-space"> </span>
    FpSpread1.ActiveSheet.RowHeader.Columns[0].Width = s;</span></span>

    I hope it will help you.



  • Replied 8 September 2017, 2:25 pm EST

    Thanks Sir. I did the job

    I was using this Spread.ActiveSheet.Models.RowHeaderColumnAxis.SetSize(0, (int)Spread.ActiveSheet.GetPreferredColumnWidth(0)) which was not correct 

  • Replied 8 September 2017, 2:25 pm EST

    This works, but messes up the other display settings on my column headers.  They switch to having flat color (rather than chrome) and the filter and sort icons disappear.

     Any suggestions?

     Thank you!

  • Replied 8 September 2017, 2:25 pm EST

    Use the GetPreferredColumnWidth method...

        fpSpread1.Sheets[0].Columns[0].Width = fpSpread1.Sheets[0].GetPreferredColumnWidth(0);

  • Replied 8 September 2017, 2:25 pm EST


    Instead of setting the celltype you may set the wrodwrap false for column header renderer. for example:

    Dim columnHeaderRenderer As New FarPoint.Win.Spread.CellType.EnhancedColumnHeaderRenderer

            columnHeaderRenderer.WordWrap = False

            FpSpread1.Sheets(0).ColumnHeader.Cells(0, 0).Renderer = columnHeaderRenderer

            Dim col As FarPoint.Win.Spread.Column

            Dim size As Single

            col = FpSpread1.ActiveSheet.ColumnHeader.Columns(0)

            size = col.GetPreferredWidth()

            col.Width = size




Need extra support?

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

Learn More

Forum Channels