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.



      
     
    <span class="kwd">Private Sub</span> Button1_Click(<span class="kwd">ByVal</span> sender <span class="kwd">As</span> System.<span class="kwd">Object</span>, <span class="kwd">ByVal</span> e <span class="kwd">As</span> System.EventArgs) <span class="kwd">Handles</span> Button1.Click
    <span class="kwd">Dim</span> row <span class="kwd">As</span> FarPoint.Win.Spread.Row
    <span class="kwd">Dim</span> col <span class="kwd">As</span> FarPoint.Win.Spread.Column

    <span class="kwd">Dim</span> sizecol <span class="kwd">As Single</span>

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

    FpSpread1.ActiveSheet.Cells(0, 0).Text = <span class="st">"This text is used to determine the height and width."</span>

    sizecol = col.GetPreferredWidth()

    col.Width = sizecol


    <span class="kwd">End Sub

    Private Sub</span> Button2_Click(<span class="kwd">ByVal</span> sender <span class="kwd">As</span> System.<span class="kwd">Object</span>, <span class="kwd">ByVal</span> e <span class="kwd">As</span> System.EventArgs) <span class="kwd">Handles</span> Button2.Click
    <span class="kwd">Dim</span> row <span class="kwd">As</span> FarPoint.Win.Spread.Row
    <span class="kwd">Dim</span> col <span class="kwd">As</span> FarPoint.Win.Spread.Column

    <span class="kwd">Dim</span> sizecol <span class="kwd">As Single</span>



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

    FpSpread1.ActiveSheet.Cells(0, 0).Text = <span class="st">"Smaller text "</span>

    sizecol = col.GetPreferredWidth()

    col.Width = sizecol


    <span class="kwd">End Sub</span>

     
  • 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