Table fixed width in RichTextBox

2 posts, 0 answers
  1. Jean
    Jean avatar
    1 posts
    Member since:
    Nov 2012

    Posted 21 Nov 2012 Link to this post

    Hey there,

    I am having troubles rerendering/reloading/reimporting the fixed/preferred width of a table within the RichTextBox:

    Here is how I insert my table:

    var table = new Table
                                Borders = new TableBorders(new Border(1, Telerik.WinControls.RichTextBox.Model.BorderStyle.Single, Color.Black)),
                                LayoutMode = TableLayoutMode.Fixed,
                                PreferredWidth = new TableWidthUnit(200) 
                for (int i = 0; i < 2; i++)
                    var row = new TableRow();
                    for (int j = 0; j < 2; j++)
                        var cell = new TableCell
                            Background = Color.White,
                            Padding = new Padding(3)
                        var paragraph = new Paragraph();
                        var span = new Span { Text = "c"+ i + j };

    This works fine. The RichTextBox control inserts the table with the preferred width. The HTML code it creates after exporting is:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
          <style type="text/css">  .p_384D933F { margin: 0px 0px 0px 0px;text-align: left;text-indent: 0pt;padding: 0px 0px 0px 0px; }   .s_6BF1D20F { font-family: 'Calibri';font-style: normal;font-size: 16px;color: #000000; }   .p_CC664AAA { margin: 0px 0px 12px 0px;text-align: left;text-indent: 0pt;padding: 0px 0px 0px 0px; }   .tbl_77AF2C2D { border-collapse: collapse;table-layout: fixed;width: 200px; }   .tc_C0034B80 { border-left: 1px solid #000000;border-top: 1px solid #000000;border-right: 1px solid #000000;border-bottom: 1px solid #000000;padding: 3px 3px 3px 3px;background-color: #FFFFFF;vertical-align: top; }   </style>
          <p class="p_384D933F"><span class="s_6BF1D20F"> </span></p>
          <table class="tbl_77AF2C2D">
                <td class="tc_C0034B80" align="left" valign="top">
                   <p class="p_CC664AAA"><span class="s_6BF1D20F">c00</span></p>
                <td class="tc_C0034B80" align="left" valign="top">
                   <p class="p_CC664AAA"><span class="s_6BF1D20F">c01</span></p>
                <td class="tc_C0034B80" align="left" valign="top">
                   <p class="p_CC664AAA"><span class="s_6BF1D20F">c10</span></p>
                <td class="tc_C0034B80" align="left" valign="top">
                   <p class="p_CC664AAA"><span class="s_6BF1D20F">c11</span></p>
          <p class="p_384D933F"><span class="s_6BF1D20F"> </span></p>

    Rendering it in any browser also works fine. The table's width is still 200.

    However, if I try to import that HTML into the RichTextBox control again:

    IDocumentFormatProvider provider = new HtmlFormatProvider();
               Byte[] convertedText = Encoding.ASCII.GetBytes(htmlStream);
               RadDocument document = provider.Import(convertedText);
               richTextBox.Document = document;

    The RichTextBox control renders the table with auto-fit style, means the table's fixed width 200 renders incorrectly.

    Am I doing anything wrong in the import call or is this a bug in the control?


  2. Svett
    Svett avatar
    728 posts

    Posted 23 Nov 2012 Link to this post

    Hello Jean,

    I managed to reproduce the issue. It seems that PreferredWidth property is not imported/exported correctly. I logged the issue in our Public Issue Tracking System. Meanwhile, you need to use the following code snippet:

    RadDocument document = provider.Import(fs);
    richTextBox.Document = document;
    foreach (Table t in richTextBox.Document.EnumerateChildrenOfType<Table>())
        t.PreferredWidth = new TableWidthUnit(200);

    I updated your Telerik points for the feedback.

    All the best,
    the Telerik team
    Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
Back to Top