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

Add Hyperlink to TableCell

1 Answer 25 Views
RichTextBox (obsolete as of Q3 2014 SP1)
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Alex asked on 24 Jul 2014, 02:02 PM
I'm attempting to add a Hyperlink to a Table and need some guidance on how to implement correctly. Below is the method that I'm using that I modified from another post. When it runs it appears to add the row correctly however all I see are blank lines in the cells that contain the Hyperlinks. 

01.private TableRow AddNewRow(object[] items)
03.    TableRow newRow = new TableRow();
04.    for (int i = 0; i < items.Length; i++)
05.    {
06.        TableCell cell = new TableCell();
07.        Paragraph paragraph = new Paragraph();
08.        Span span = new Span();
10.        if(items[i] is string)
11.        {
12.            var newString = items[i] as string;
13.            if (string.IsNullOrEmpty(newString)) newString = "No available information";
14.            span.Text = newString;
15.            paragraph.Inlines.Add(span);
16.        }
17.        else if(items[i] is HyperlinkInfo)
18.        {
19.            var hyperlinkInfo = items[i] as HyperlinkInfo;
20.            HyperlinkRangeStart hyperlinkStart = new HyperlinkRangeStart();
21.            hyperlinkStart.HyperlinkInfo = hyperlinkInfo;
22.            HyperlinkRangeEnd hyperlinkEnd = new HyperlinkRangeEnd();
23.            hyperlinkEnd.PairWithStart(hyperlinkStart);
24.            span.Text = hyperlinkInfo.ToString();
25.            paragraph.Inlines.Add(hyperlinkStart);
26.            paragraph.Inlines.Add(hyperlinkEnd);
27.        }
28.        cell.Blocks.Add(paragraph);
29.        newRow.Cells.Add(cell);
30.    }
31.    return newRow;

1 Answer, 1 is accepted

Sort by
Dess | Tech Support Engineer, Principal
Telerik team
answered on 29 Jul 2014, 08:48 AM
Hello Alex,

Thank you for writing.

You need to insert some text or image between the HyperlinkRangeStart and the HyperlinkRangeEnd, which will represent the actual item which the user needs to click (pressing the Ctrl key) to open the hyperlink. Here is a sample code snippet:
public Form1()
private void CreateTable()
    Section section = new Section();
    Table table = new Table();
    TableRow row1 = new TableRow();
    TableCell cell1 = new TableCell();
    Paragraph p1 = new Paragraph();
    Span s1 = new Span();
    s1.Text = "Cell 1";
    TableCell cell2 = new TableCell();
    Paragraph p2 = new Paragraph();
    Span s2 = new Span();
    s2.Text = "Cell 2";
    TableRow row2 = new TableRow();
    TableCell cell3 = new TableCell();
    cell3.ColumnSpan = 2;
    Paragraph p3 = new Paragraph();
    Span s3 = new Span();
    s3.Text = "Cell 3";
private void radButton1_Click(object sender, EventArgs e)
    Section tableSection = this.radRichTextBox1.Document.Sections.First();
    Table table = tableSection.Blocks.First() as Table;
    if (table != null)
        TableRow newRow = new TableRow();
        TableCell cell = new TableCell();
        cell.ColumnSpan = 2;
        HyperlinkRangeStart hyperlinkStart = new HyperlinkRangeStart();
        HyperlinkRangeEnd hyperlinkEnd = new HyperlinkRangeEnd();
        HyperlinkInfo hyperlinkInfo = new HyperlinkInfo()
            NavigateUri = "",
            Target = HyperlinkTargets.Blank
        hyperlinkStart.HyperlinkInfo = hyperlinkInfo;
        Paragraph paragraph = new Paragraph();
        Span span = new Span("Hyperlink");               

Please refer to our Hyperlink help article, which is useful about this topic.

I hope this information helps. Should you have further questions, I would be glad to help.
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
RichTextBox (obsolete as of Q3 2014 SP1)
Asked by
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question