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
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;
}
}
Greetings,
Iva Toteva
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
I get the value 0 (zero) always for tableRow.FirstLayoutBox.ControlBoundingRectangle.Height
Do I need to consider anything else
Thanks
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
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 >>
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.
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.