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

How to access table object in richtextbox or raddocument

1 Answer 175 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Mahesh Mitkari
Top achievements
Rank 2
Mahesh Mitkari asked on 28 Feb 2012, 10:42 AM
HI

I am using richtext box in which i import a Microsoft word document as a rad document using the docx provider class and then i am binding the imported raddocument to document property of richtextbox.

in the word document which i am importing, i already have some tables, i want to programmatically access them and do some operations (update/delete etc based on some logic) on them before i allow user to edit the document or save it in any required format.

my current problem is, I am not able to find out any class or methods which i can use for this operation, no method is available which i can use the get the table or list of tables in the raddocument or richtexbox.

my first question is Can we do this in richtextbox or raddocument? do we have any methods available to access the tables in the raddocument or richtextbox ?

if yes can you please point me some documentation or some demo for the same.

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 02 Mar 2012, 02:18 PM
Hi Mahesh,

Here is a small demonstration of manipulating all existing tables in the current document. It should give you a an idea of the document structure and how you can interact with the document elements in code-behind.

var tables = this.radRichTextBox1.Document.EnumerateChildrenOfType<Table>();
foreach (Table table in tables)
{
    foreach (TableRow row in table.Rows)
    {
        foreach (TableCell cell in row.Cells)
        {
            foreach (Block block in cell.Blocks)
            {
                Paragraph para = block as Paragraph;
                if (para != null)
                {
                    InlineLayoutBox firstInlineLayoutBox = para.Inlines.First.FirstLayoutBox as InlineLayoutBox;
                    this.radRichTextBox1.Document.CaretPosition.MoveToInline(firstInlineLayoutBox, 0);
                    this.radRichTextBox1.InsertInline(new Span("ok"));
                }
            }
        }
    }
}

In our documentation there is a schema of the document elements tree here:  http://www.telerik.com/help/silverlight/radrichtextbox-features-document-elements-hierarchy.html .

After you have found the document element you want, you can get the inline element in it you want to navigate to and move the caret position to it. After you have moved the caret to the place in the document you want to edit, you can use the methods from RadRichTextBox's API for inserting text, inlines, etc. More information on document positions is available here.

We hope this will help you. If you are having any other difficulties with the table elements manipulation, do not hesitate to contact us again. Regards,
Martin
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
RichTextBox
Asked by
Mahesh Mitkari
Top achievements
Rank 2
Answers by
Martin Ivanov
Telerik team
Share this question
or