Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
765
Understanding the Auto Height mechanism of grid cells
posted

Hi

I have a grid and I need to know in advance what the grid height will be . The cells height are Auto Height  and the grid column widths are fixed.

By default the grid adjusts the height of the cells according to the width and the amount of text . That is Ok but I want to know in advance what the height of each cell is going to be , and for that I need to know how many lines of text are going to be in the cell. I tried measuring the text on a canvas for each cell and then dividing by the width of the cell, but the problem is that the cell (or the IText not sure who ) does  word wrap , so sometimes the height will actually be more becuase it tries not to break up the words and for that it sometimes uses more lines.

I already asked a question on how to remove the Word Wrap feature , but I would also like to know how I can calculate the actual height with word wrap . What is the algorithm it used to calculate how to break up the text into different lines. If there is an easy way for me to find out how many lines of text there are in each cell then I think that would be the best solution. 

Thanks.

Parents
  • 37774
    posted

    I'm not sure that there's an easy way to do this.  The Documents engine does its measuring in several passes, and is also dependant on the parent/sibling elements and how much space they take up.  Since the Documents engine will not break apart words when wrapping, what you could do is measure each word, and if there isn't enough space for that word, you know it's on the next line, so you could continue your measuring that way.  There is a static private method in the GraphicsProxy class in the Documents assembly called BuildMultiLineString that you could take a look at that basically does this, taking into account spaces and newlines.

    -Matt

Reply Children
No Data