How to determine the Actual Height of a TableRow in RadDocument

6 posts, 0 answers
  1. Koen Van Wijmeersch
    Koen Van Wijmeersch avatar
    6 posts
    Member since:
    Dec 2009

    Posted 20 Apr 2012 Link to this post


    I'm creating a RadDocument from code and would like to be able to
    determine the actual height of a specific tableRow.

    I actually have two tables, and would like to have all the rows to have the same height ( = max of both tables):

    for (int i = 0; i < rouwCount; i++)
        var maxHeight = tables.Max(x => x.Rows.ElementAt(i).Height);
        foreach (var table in tables)
            table.Rows.ElementAt(i).Height = maxHeight;

    However, the height property is always zero. I understand this is not the actual height, is there a way to determine this?


  2. Iva Toteva
    Iva Toteva avatar
    1319 posts

    Posted 25 Apr 2012 Link to this post

    Hi Koen,

    The Height property of a TableRow is only set when you import a document that specifies explicitly the Height of table rows, you copy/paste such a row or you change the height of a TableRow using the DocumentRuler (or the thumbs that are shown when you hover the Table). In general, the document takes care to calculate the Height of a table when you enter text in it, so in the other cases, it is not set.

    What you can do, is to use the height of the control bounding rectangle after the document has been measured. Here is the code that calculates the height of the biggest row in all tables in the document and sets this value to each row:

    IEnumerable<Table> tables = document.EnumerateChildrenOfType<Table>(); //or get the tables in some other way
    float maxHeight = 0;
    //find max height
    foreach (Table table in tables)
        foreach (TableRow tableRow in table.Rows)
            if (tableRow.FirstLayoutBox.ControlBoundingRectangle.Height > maxHeight)
                maxHeight = tableRow.FirstLayoutBox.ControlBoundingRectangle.Height;
    //set the height of the rows to the max value
    foreach (Table table in tables)
        foreach (TableRow tableRow in table.Rows)
            tableRow.Height = maxHeight;                  

    I hope this helps.
    Iva Toteva
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. Anthony
    Anthony avatar
    1 posts
    Member since:
    Oct 2013

    Posted 16 Jan 2014 Link to this post

    Hi Iva,
    I get the value 0 (zero) always for tableRow.FirstLayoutBox.ControlBoundingRectangle.Height

    Do I need to consider anything else

  4. Yancho
    Yancho avatar
    72 posts

    Posted 20 Jan 2014 Link to this post

    Hi Anthony,

    If you are going to determine the actual height of a TableRow in RadDocument, you should create a RadDocument with data in its table. Also, please be aware that the document should be manually measured and arranged before you begin to calculate the height of a row. Additionally note that it is recommended to modify a measured document only using methods of RadRichTextBox or RadDocumentEditor.

    Please, take a look at the following code-snippet which demonstrates how to measure and arrange a document:
    document.LayoutMode = DocumentLayoutMode.Paged;

    However, if this is not the case, please give us more information. This way we are going to further investigate your scenario.

    Please let me know, if I can provide any further assistance. 

    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  5. C
    C avatar
    43 posts
    Member since:
    Jul 2014

    Posted 01 Oct 2014 in reply to Yancho Link to this post

    We have a similar question.  How can we create a table programmatically in C# code with a single row of height 0.25 inch with the text 'abc' in 4 point font?

    We need a thin table to divide sections in a larger word document.  This is for a RadDocument created in C# code with no XAML and not creating a RichTextBox control.
  6. Petya
    Petya avatar
    990 posts

    Posted 06 Oct 2014 Link to this post


    The task is pretty straightforward - you just need to set the respective properties while creating the Table element. Make sure to convert your measuring units to Dip, as this is the default measuring unit when editing elements in code.
    Table table = new Table() { StyleName = RadDocumentDefaultStyles.DefaultTableGridStyleName };
    TableRow row = new TableRow();
    row.Height = Unit.InchToDip(0.25);
    TableCell cell = new TableCell();
    Paragraph p = new Paragraph();
    p.Inlines.Add(new Span("test") { FontSize = Unit.PointToDip(4) });


    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top