Question about Telerik.Windows.Documents.Model.TableCell

4 posts, 0 answers
  1. Kjell
    Kjell avatar
    283 posts
    Member since:
    Jun 2010

    Posted 26 Apr 2011 Link to this post

    Is it possible to have a cell stretch across multiple columns?  Basically what you would do with "colspan=x" in an HTML table.

    I have a table with 5 columns, I am adding rows programatically and every other row I want to have all the cells combined.  I can get rid of the borders to give the illusion, but the text still gets crammed into one cell.  So either I need a way to make one cell stretch across the 5 columns, or to have the text go across multiple cells.  Here is the void which adds the text to the cells:

    private void AddCellDataSpan(TableCell cell, string spanData, Color cellBackgroundColor, Color textColor, Telerik.Windows.Documents.Layout.RadTextAlignment cellTextAligment)
          {
              var paragraph = new Telerik.Windows.Documents.Model.Paragraph();
              paragraph.TextAlignment = cellTextAligment;
              cell.Blocks.Add(paragraph);
              cell.Background = cellBackgroundColor;
              var span = new Telerik.Windows.Documents.Model.Span();
              span.Text = spanData;
              span.ForeColor = textColor;
              span.FontSize = 9;
              paragraph.Inlines.Add(span);
          }
  2. Andrew
    Admin
    Andrew avatar
    140 posts

    Posted 02 May 2011 Link to this post

    Hello Kjell,

    You can use MergeTableCells() method of RadRichTextBox. What it does is actually merging all selected cells into one. You can use the following code before or after your method is executed.

    private void MergeCellsOnFirstRow(TableCell cell)
    {
         TableRow row = cell.Row;
         for (int i = 0; i < row.Cells.Count; i++)
         {
               this.radRichTextBox1.Document.Selection.AddTableCellToSelection(row.Cells.ToArray()[i]);
         }
         this.radRichTextBox1.MergeTableCells();
         this.radRichTextBox1.Document.Selection.Clear();
    }

    If this doesn't help, contact us again.

    Kind regards,
    Andrew
    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
  3. Kjell
    Kjell avatar
    283 posts
    Member since:
    Jun 2010

    Posted 02 May 2011 Link to this post

    Sorry, I should have been more specific.  I am not using the radrichtextbox, I am creating the table as part of the PDF export from radgridview.  I got this code from one of the Telerik blogs but don't have the link handy.
  4. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 06 May 2011 Link to this post

    Hi Kjell,

    You can use the ColumnSpan property of the TableCell to achieve what you want. It work in a similar way as the "colspan" attribute in HTML.

    For more information you can review our online documentation regarding the programmatic creation of Tables. There is also a sample project in this forum thread (CodeBehindDocument, Feb 17).
    I hope that helps.

    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
Back to Top