This is a migrated thread and some comments may be shown as answers.

How to determine the Actual Height of a TableRow in RadDocument

5 Answers 799 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Koen Van Wijmeersch
Top achievements
Rank 1
Koen Van Wijmeersch asked on 20 Apr 2012, 02:30 PM
Hi,

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?

Thanks,

Koen

5 Answers, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 25 Apr 2012, 12:33 PM
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:

document.EnsureDocumentMeasuredAndArranged();
 
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.
 
Greetings,
Iva Toteva
the Telerik team

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

0
Anthony
Top achievements
Rank 1
answered on 16 Jan 2014, 04:40 PM
Hi Iva,
I get the value 0 (zero) always for tableRow.FirstLayoutBox.ControlBoundingRectangle.Height

Do I need to consider anything else

Thanks
Anthony
0
Missing User
answered on 20 Jan 2014, 11:37 AM
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;
document.MeasureAndArrangeInDefaultSize();

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. 

Regards,
Yancho
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
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 >>
0
C
Top achievements
Rank 1
answered on 01 Oct 2014, 10:49 PM
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.
0
Petya
Telerik team
answered on 06 Oct 2014, 02:25 PM
Hi,

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) });
cell.Blocks.Add(p);
 
row.Cells.Add(cell);
table.Rows.Add(row);

Regards,
Petya
Telerik
 

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.

 
Tags
RichTextBox
Asked by
Koen Van Wijmeersch
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Anthony
Top achievements
Rank 1
Missing User
C
Top achievements
Rank 1
Petya
Telerik team
Share this question
or