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

How to Find Table in RichTextbox

1 Answer 207 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Sajid
Top achievements
Rank 1
Sajid asked on 08 Aug 2012, 06:11 AM
Sir,

I have a table in a richtextbox. I want to insert rows and columns at runtime to that table. Is it possible to add rows and columns to an existing table.

1- Find that table
2- Insert Rows/Columns to this table

Regards
M. Rizwan

1 Answer, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 09 Aug 2012, 09:29 AM
Hi M. Rizwan,

You can use the EnumerateChildrenOfType<Table>() method of RadDocument . In fact, all document elements have this method, which enables you to search for particular document elements which have a specific parent. For example, the following code will return the tables only in the first section of the document:

var tablesInFirstSection = this.editor.Document.Sections.First.EnumerateChildrenOfType<Table>() ;

As for inserting rows and columns in a table, you can use the following methods:
this.editor.InsertTableRowAbove();
this.editor.InsertTableRowBelow();
this.editor.InsertTableColumnToTheLeft();
this.editor.InsertTableColumnToTheRight();

These methods insert a table row relatively to the caret position and can only be executed when the caret is positioned in a table. Here is an example how you can move the document position to the beginning of the first cell in a table:
Inline inlineInTable = table.Rows.First.Cells.First.Blocks.First.EnumerateChildrenOfType<Inline>().First();
this.editor.Document.CaretPosition.MoveToInline(inlineInTable);


Kind regards,
Iva Toteva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
RichTextBox
Asked by
Sajid
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Share this question
or