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

Table fixed width in RichTextBox

1 Answer 276 Views
RichTextBox (obsolete as of Q3 2014 SP1)
This is a migrated thread and some comments may be shown as answers.
Jean
Top achievements
Rank 1
Jean asked on 21 Nov 2012, 06:16 PM
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 };
 
                    paragraph.Inlines.Add(span);
                    cell.Blocks.Add(paragraph);
                    row.Cells.Add(cell);
                }
 
                table.Rows.Add(row);
            }
            this.richTextBox.InsertTable(table);


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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>Untitled</title>
      <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>
   </head>
   <body>
      <p class="p_384D933F"><span class="s_6BF1D20F"> </span></p>
      <table class="tbl_77AF2C2D">
         <tr>
            <td class="tc_C0034B80" align="left" valign="top">
               <p class="p_CC664AAA"><span class="s_6BF1D20F">c00</span></p>
            </td>
            <td class="tc_C0034B80" align="left" valign="top">
               <p class="p_CC664AAA"><span class="s_6BF1D20F">c01</span></p>
            </td>
         </tr>
         <tr>
            <td class="tc_C0034B80" align="left" valign="top">
               <p class="p_CC664AAA"><span class="s_6BF1D20F">c10</span></p>
            </td>
            <td class="tc_C0034B80" align="left" valign="top">
               <p class="p_CC664AAA"><span class="s_6BF1D20F">c11</span></p>
            </td>
         </tr>
      </table>
      <p class="p_384D933F"><span class="s_6BF1D20F"> </span></p>
   </body>
</html>

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?

Thanks,
Jean


1 Answer, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 23 Nov 2012, 02:03 PM
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);
}
 
richTextBox.DocumentView.UpdateEditorLayout();

I updated your Telerik points for the feedback.

All the best,
Svett
the Telerik team
Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
Tags
RichTextBox (obsolete as of Q3 2014 SP1)
Asked by
Jean
Top achievements
Rank 1
Answers by
Svett
Telerik team
Share this question
or