GridViewHyperlinkColumn Appearance

4 posts, 0 answers
  1. Todd
    Todd avatar
    9 posts
    Member since:
    May 2011

    Posted 25 Mar 2015 Link to this post

    Hi, 

    Please provide a code snippet to customize the appearance of the GridViewHyperlinkColumn cells. I'm trying to define the state of a cell based on the help topic at GridViewHyperlinkColumn Appearance.
  2. Todd
    Todd avatar
    9 posts
    Member since:
    May 2011

    Posted 26 Mar 2015 in reply to Todd Link to this post

    I've found a workaround at HTML-like Text Formatting. The stylizing piece of code should basically be placed within the GridView CellFormatting event handler:

    private void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
    {
        if (e.CellElement is GridHyperlinkCellElement)
        {
            e.CellElement.Text = String.Format("<html><color=0,0,255>{0}", e.CellElement.Text);
        }
    }
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 30 Mar 2015 Link to this post

    Hello Todd,

    Thank you for writing.

    Indeed, the CellFormatting event is used to add formatting to grid data cells. Here is a sample code snippet demonstrating how to customize the GridHyperlinkCellElement's style:
    public Form1()
    {
        InitializeComponent();
        GridViewHyperlinkColumn column = new GridViewHyperlinkColumn();
        column.Name = "Hyperlink column";
        this.radGridView1.Columns.Add(column);
        this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
     
        this.radGridView1.Rows.Add("http://www.telerik.com");
        this.radGridView1.Rows.Add("http://www.microsoft.com");
        this.radGridView1.Rows.Add("http://www.google.com");
        this.radGridView1.Rows.Add("http://www.cnn.com");
        this.radGridView1.Rows.Add("http://www.bbc.com");
        this.radGridView1.Rows.Add("http://www.telerikwatch.com/");
        this.radGridView1.Rows.Add("http://www.wikipedia.com");
    }
     
    private void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
    {
        GridHyperlinkCellElement hyperlinkCell = e.CellElement as GridHyperlinkCellElement;
        if (hyperlinkCell != null)
        {
            GridViewHyperlinkCellInfo cellInfo = e.Row.Cells[e.Column.Name] as GridViewHyperlinkCellInfo;
            if (cellInfo.Visited)
            {
                hyperlinkCell.ContentElement.Text = String.Format("<html><color=0,0,255>{0}", e.CellElement.Text);
            }
            else
            {
                hyperlinkCell.ContentElement.Text = String.Format("<html><color=yellow>{0}", e.CellElement.Text);
            }
        }
    }

    I hope this information helps. Should you have further questions, I would be glad to help.
     
    Regards,
    Dess
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  5. Todd
    Todd avatar
    9 posts
    Member since:
    May 2011

    Posted 08 Apr 2015 in reply to Dess Link to this post

    Thanks, Dess! Here's the more complete reference of the HTML tags for formatting that I've found:

     HTML-like Text Formatting

     

Back to Top