Using Row.GetPreferredHeight() returns invalid row heights.

Posted by: krishna.vajja on 28 May 2020, 6:47 pm EST

  • Posted 28 May 2020, 6:47 pm EST

    Hi,

    We are facing an issue with GetPreferredHeight().
    If we merge more than two rows and columns and both multiline and wordwrap are set to true
    And then try to get the preferred height of the row based on the text given,
    we are getting the output height more than the size of the text.
    But if we use the method for single row and multiple columns merge and both wordwrap and multiline are set to true,
    the method is giving us the correct size of the row based on the text given.

    Please help us asap in resolving this issue.

    Thanks,
    Krishna.
  • Replied 28 May 2020, 6:48 pm EST

    Untitled1.zipUntitled2.zip
  • Replied 29 May 2020, 12:03 am EST

    Hello,

    I have escalated the issue to the development team(SPNET-7694) and will inform you once I get any information from them.

    Thanks,
    Mohit
  • Marked as Answer

    Replied 1 June 2020, 6:53 pm EST

    Hello,

    As per the developer, it is by design. PreferredHieght doesn't work on the merge cell.

    Thanks,
    Mohit
  • Replied 20 January 2021, 9:42 pm EST

    Hi Mohit,

    We got a requirement for applying wordwrap on a merged cell(across multiple rows and columns).
    Do you have any future plans for that?
    Please let us know.

    Thanks,
    Krishna
  • Replied 20 January 2021, 10:43 pm EST

    Hi Mohit,

    In the earlier reply you said that WrapText doesn't work for merged cells. But, when I verified it in Spread Designer v12, wrap text was working fine when a cell is merged across multiple columns and rows.
    Can you let us know the details of methods for applying wordwrap for merge cells in the code.

    Thanks,
    Krishna
  • Replied 21 January 2021, 6:37 pm EST

    Hi Krishna,

    In the earlier post, Mohit meant that the GetPreferredHeight method does not work (correctly) when there are Merged cells since merged cells are ignored while calculating preferred height/width.

    You can apply WordWrap using:
    fpSpread1.ActiveSheet.Cells[1, 1].ColumnSpan = 2;
    fpSpread1.ActiveSheet.Cells[1, 1].RowSpan = 2;

    var cellType = new GeneralCellType();
    cellType.WordWrap = true;
    fpSpread1.ActiveSheet.Cells[1, 1].CellType = cellType;


    Regards,
    Jitender
  • Replied 21 January 2021, 8:16 pm EST

    Hi Jitender,

    Thanks for the solution.
    We were using wordwrap property since long time and the property has driven by GetPreferredRowHeight() method. This method is doing the job for us except while multiple rows are merged.
    I understand you have given us a new option now, but both the properties have slight differences. If we start using the new option, our clients who have to upgrade to new version will face issues and would not be ready to that.
    Hence, I request you to provide a fix for for the issues we are facing while using GetPreferredRowHeight(). I think you will also understand how incorrectly the method works when multiple rows are merged and the method is applied on it.

    I am also attaching the screenshot of the issue we are facing.
  • Replied 28 January 2021, 4:28 am EST

    Hi,
    Awaiting a response for the above query.

    Regards,
    Krishna.
  • Replied 28 January 2021, 10:48 pm EST

    Hi,

    The behavior of GetPreferredRowHeight is consistent with the way Excel works. In Excel also, if you merge multiple cells with WordWrap then the row height is not increased to accommodate the content because the merged cells are not considered in the calculation.

    Please refer to the attached sample which uses the cell Renderer to set the row height so that the content is still visible with WordWrap.

    MergedRowPrefHeight.zip

    Regards,
    Jitender
  • Replied 16 March 2021, 11:24 pm EST

    Damm even I am having a similar kind of issue, I have searched all over the internet and even have posted on number of threads on different forum, no solution seems to work. I am really frustrated, can anyone of you here help me resolve this issue, I am very much tired now.
  • Replied 4 April 2021, 7:51 pm EST

    Hi,

    Please refer the sample attached in the previous post:
    https://www.grapecity.com/forums/c1-studio/using-rowgetpreferredheigh#hithe-behavior-of-getprefe

    The sample demonstrates how you can correctly calculate the preferred row heights when multiple rows are merged.
    Let us know if you face any issues in using the sample.

    Regards,
    Jitender
Need extra support?

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

Learn More

Forum Channels