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

How to Remove GridViewHyperlinkColumn in GridView

3 Answers 214 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Velkumar
Top achievements
Rank 1
Velkumar asked on 05 Dec 2012, 10:49 AM
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.




3 Answers, 1 is accepted

Sort by
0
Anton
Telerik team
answered on 07 Dec 2012, 11:58 AM
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.
0
Joshua
Top achievements
Rank 1
answered on 08 May 2013, 06:36 PM
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?
0
Anton
Telerik team
answered on 13 May 2013, 02:40 PM
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?
Tags
GridView
Asked by
Velkumar
Top achievements
Rank 1
Answers by
Anton
Telerik team
Joshua
Top achievements
Rank 1
Share this question
or