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

    Hi,

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

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

     

    Thanks. 

  • Replied 8 September 2017, 2:25 pm EST

    thanks for the GetPreferredColumnWidth  but in VB 6.0 version when we pass zero it means "row headers"

    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

    Use the GetPreferredColumnWidth method...


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

  • Replied 8 September 2017, 2:25 pm EST

    Hello,

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

    fpSpread1.ActiveSheet.ColumnHeader.Columns(0).Width.

    Below is an example to achieve the same:

    FarPoint.Win.Spread.CellType.GeneralCellType g = new FarPoint.Win.Spread.CellType.GeneralCellType(); 
    g.WordWrap = false; 
    fpSpread1.ActiveSheet.RowHeader.Columns[0].CellType = g; 
    fpSpread1.ActiveSheet.RowHeader.Cells[0, 0].Text = "This is a test string"; 
    float s = fpSpread1.ActiveSheet.RowHeader.Columns[0].GetPreferredWidth; 
    FpSpread1.ActiveSheet.RowHeader.Columns[0].Width = s;

    I hope it will help you.

    Thanks,

     

  • 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

    Hello,

    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

    Thanks,

     

     

Need extra support?

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

Learn More

Forum Channels