GetPreferredWidth wont return smaller value if cell changed to contain less text.

Posted by: brosmi on 8 September 2017, 1:10 pm EST

  • Posted 8 September 2017, 1:10 pm EST

    If I enter a long text in a cell and then call GetPreferredWidth it returns the correct value.
    If I then change the text to contain a smaller value I would then expect GetPreferredWidth to return the smaller size but it returns the size of the first value.


    Sample (Button1 = Large Text) (Button2=Smaller Text)
    Click Button1 and then click button2.



      
     
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim row As FarPoint.Win.Spread.Row
    Dim col As FarPoint.Win.Spread.Column

    Dim sizecol As Single

    row = FpSpread1.ActiveSheet.Rows(0)
    col = FpSpread1.ActiveSheet.Columns(0)

    FpSpread1.ActiveSheet.Cells(0, 0).Text = "This text is used to determine the height and width."

    sizecol = col.GetPreferredWidth()

    col.Width = sizecol


    End Sub

    Private Sub
    Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Dim row As FarPoint.Win.Spread.Row
    Dim col As FarPoint.Win.Spread.Column

    Dim sizecol As Single



    row = FpSpread1.ActiveSheet.Rows(0)
    col = FpSpread1.ActiveSheet.Columns(0)

    FpSpread1.ActiveSheet.Cells(0, 0).Text = "Smaller text "

    sizecol = col.GetPreferredWidth()

    col.Width = sizecol


    End Sub

     
  • Replied 8 September 2017, 1:10 pm EST

    brasmi -

    The GetPreferredWidth doesn't have a way to exclude the header, so after the first call in button1 the width of the header is set and the call in button2 will not reset the width of the header.  You need to use the GetPreferredColumnWidth method instead and set the parameter to ignore the headers.
Need extra support?

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

Learn More

Forum Channels