GetPreferredWidth() Question

Posted by: scottw-fp on 8 September 2017, 2:06 pm EST

  • Posted 8 September 2017, 2:06 pm EST

    I'm using version 3.0.2010.2005.  I'm trying to figure out how the various GetPreferredWidth() fxns should work.  I have a column header and the WordWrap is set to true.  When I call GetPreferredWidth(iColumn, false, true, true) I would expect the fxn to return a width that factors in the WordWrap column but it doesn't appear to be doing that.  Could you please explain how the WordWrap is supposed to be handled in the various GetPreferredWidth fxns?
  • Replied 8 September 2017, 2:06 pm EST

    <p>Hello,</p><p>When you have word wrap set to True the Width is getting re sized in accordance with the cell for Text not with the Headers cells.</p><p>You need to turn WordWrap Off in order to set the ColumnWidth according to the width of the Text inside a cell.</p><p>I hope it helps you.</p><p> </p><p>Thanks,</p><p> </p>
  • Replied 8 September 2017, 2:06 pm EST

    <P>Hello,</P>
    <P>The problem you mention is a royal pain and one of the few things about spread that drive me nuts. For every project, I create a SetupSheetView method like this:</P>
    <P>    Private Sub SetupFarPointSheetView(ByVal sheet As SheetView)<BR>        Try<BR>            With sheet<BR>                .SelectionUnit = Model.SelectionUnit.Cell<BR>                .DataAutoSizeColumns = False</P>
    <P>                ' Set row headers to no wrap.<BR>                Dim rowRendererNoWrapText As New CellType.RowHeaderRenderer<BR>                rowRendererNoWrapText.WordWrap = False<BR>                .RowHeader.DefaultStyle.Renderer = rowRendererNoWrapText</P>
    <P>                ' Set column headers to no wrap.<BR>                Dim columnRendererNoWrapText As New CellType.ColumnHeaderRenderer<BR>                columnRendererNoWrapText.WordWrap = False<BR>                .ColumnHeader.DefaultStyle.Renderer = columnRendererNoWrapText<BR>            End With<BR>        Catch ex As Exception<BR>            Throw<BR>        End Try<BR>    End Sub 'SetupFarPointSheetView</P>
    <P>Once you have done the above, then you can use the sheetview GetPreferredColumnWidth method which has some overloads pertaining to column headers, spans, etc.</P>
    <P>    With Me.FpSpread1.ActiveSheet<BR>         For Each column As Column In .Columns<BR>            column.Width = .GetPreferredColumnWidth(column.Index, False)<BR>        Next<BR>    End With</P>
    <P>Good Luck! It is a great product, but does have a few gotchas here and there.<BR><BR></P>
Need extra support?

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

Learn More

Forum Channels