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

Restricting table width

1 Answer 63 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Tracey
Top achievements
Rank 1
Tracey asked on 25 May 2011, 01:15 PM
Hi

I am using the RadRichTextBox with a HtmlDataProvider as a html editor. When I add a table the width comes out in the html as 626px. This is too big for where I wish to display the html, is there any way of restricting the size of the table when it gets added?

Many Thanks
Tracey

1 Answer, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 31 May 2011, 09:04 AM
Hello Tracey,

If you are creating a document in code-behind, i.e. you know how much rows and columns the table you wish to insert has, you can use the following method from RadRichTextBox's API:

this.radRichTextBox.InsertTable(new Table(rowsCount, columnsCount) { PreferredWidth = new TableWidthUnit(myPreferredWidth) });

In case you are using the UI that comes with RadRichTextBox - RadRichTextBoxRibbonUI and are inserting tables through the TableSizePicker, you can subscribe to the DocumentElementAdded and every time a Table is added, set its preferred Width to the value you wish to use. Here is the sample code for that:
float myPreferredWidth = 300;
void Document_DocumentElementAdded(object sender, DocumentElementAddedEventArgs e)
{
    Table table = e.DocumentElement as Table;
    if (table != null)
    {
        table.PreferredWidth = new TableWidthUnit(myPreferredWidth);
        table.LayoutMode = TableLayoutMode.Fixed;
    }
}

Note that the data providers create a new document for every change in the property they are bound to. Thus, the subscription to the DocumentElementAdded event of the document must happen on document changed as follows:
private void radRichTextBox_DocumentChanged(object sender, EventArgs e)
{
    ((RadRichTextBox)sender).Document.DocumentElementAdded += Document_DocumentElementAdded;
}
 
private void radRichTextBox_DocumentChanging(object sender, EventArgs e)
{
    ((RadRichTextBox)sender).Document.DocumentElementAdded -= Document_DocumentElementAdded;
}

I hope this helps.


Kind regards,
Iva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
RichTextBox
Asked by
Tracey
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Share this question
or