How to Remove GridViewHyperlinkColumn in GridView

4 posts, 0 answers
  1. Velkumar
    Velkumar avatar
    16 posts
    Member since:
    Jul 2012

    Posted 05 Dec 2012 Link to this post

    Hi, 

    i am having RadGridView, where i have "GridViewHyperlinkColumn", i need to remove Hyperlink based on some conditions, how to do that.

    Note:- i don't want to make visible as false, just need to remove link alone.




  2. Anton
    Admin
    Anton avatar
    167 posts

    Posted 07 Dec 2012 Link to this post

    Hello Velkumar,

    Thank you for writing.

    I assume that you want the hyperlink cells to have behavior based on some condition - in some cases the cells to have normal functionality but in other cases to show only text. If so, you can do that with the following code in the CellFormatting event handler:
    GridHyperlinkCellElement gridLink = e.CellElement as GridHyperlinkCellElement;
    if (gridLink == null || e.Row.Cells["TextBoxColumn"].Value == null)
    {
        return;
    }
     
    if (e.Row.Cells["TextBoxColumn"].Value.ToString() == "bbbbb")
    {
        gridLink.ContentElement.Visibility = Telerik.WinControls.ElementVisibility.Hidden;
        e.CellElement.DrawText = true;
        e.CellElement.Text = gridLink.ContentElement.Text;
    }

    Attached is a sample project that comprises the code above.

    If this is not the case, please describe in greater details what is your goal, so I can provide you with adequate support.

    I hope this helps. Let me know if you have any additional questions.

    Greetings,
    Anton
    the Telerik team
    Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
  3. Joshua
    Joshua avatar
    1 posts
    Member since:
    May 2013

    Posted 08 May 2013 Link to this post

    I am using the code you provided, the problem is when you scroll the grid, the hyperlinks get removed for cells where I need the links to stay.  To the point where all the links are gone.  Is there a fix for that?
  4. Anton
    Admin
    Anton avatar
    167 posts

    Posted 13 May 2013 Link to this post

    Hi Joshua,

    Thank you for writing.

    In your CellFormatting event you should reset the value of the properties that you are changing, because RadGridView uses UI virtualization for its cells i.e. they are reused to display different data - see this blog for more information.

    Consider the following example:
    void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
    {
        GridHyperlinkCellElement gridLink = e.CellElement as GridHyperlinkCellElement;
        if (gridLink == null || e.Row.Cells["TextBoxColumn"].Value == null)
        {
            return;
        }
     
        if (e.Row.Cells["TextBoxColumn"].Value.ToString() == "bbbbb")
        {
            gridLink.ContentElement.Visibility = Telerik.WinControls.ElementVisibility.Hidden;
            e.CellElement.DrawText = true;
            e.CellElement.Text = gridLink.ContentElement.Text;
        }
        else
        {
            gridLink.ContentElement.ResetValue(LightVisualElement.VisibilityProperty, ValueResetFlags.Local);
            gridLink.ResetValue(LightVisualElement.DrawTextProperty, ValueResetFlags.Local);
        }
    }

    I hope this helps.

    All the best,
    Anton
    the Telerik team
    RadChart for WinForms is obsolete. Now what?
Back to Top