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

Question about Telerik.Windows.Documents.Model.TableCell

3 Answers 167 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Kjell
Top achievements
Rank 1
Kjell asked on 26 Apr 2011, 10:27 PM
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);
      }

3 Answers, 1 is accepted

Sort by
0
Andrew
Telerik team
answered on 02 May 2011, 11:59 AM
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
0
Kjell
Top achievements
Rank 1
answered on 03 May 2011, 03:22 AM
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.
0
Iva Toteva
Telerik team
answered on 06 May 2011, 07:53 AM
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
Tags
General Discussions
Asked by
Kjell
Top achievements
Rank 1
Answers by
Andrew
Telerik team
Kjell
Top achievements
Rank 1
Iva Toteva
Telerik team
Share this question
or