New to Telerik UI for WPF? Download free 30-day trial

Subscribe to Click Event in GridViewHyperlinkColumn

If you have defined a GridViewHyperlinkColumn within your RadGridView, you might need to subscribe to its "Click" event for some internal operations. This article describes two approaches that you can take.

If the first column of the RadGridView is a GridViewHyperlinkColumn, as in the picture below:

Figure1: RadGridView with GridViewHyperLinkColumn

Hyperlink Column in RadGridView - Telerik's WPF DataGrid

First Approach

You can apply the following logic in the code behind:

Subscribe to Click Event in GridViewHyperlinkColumn

    public MainWindow() 
        this.AddHandler(Hyperlink.ClickEvent, new RoutedEventHandler(hyperlinkClicked)); 
    private void hyperlinkClicked(object sender, RoutedEventArgs e) 
        Hyperlink hyperLink = e.OriginalSource as Hyperlink; 
Figure 2 shows the result after clicking the hyperlink:

Figure 2: The result after clicking the hyperlink

Clicking Hyperlink in RadGridView - Telerik's WPF DataGrid

Second Approach

Declare a standard GridViewDataColumn instead of GridViewHyperlinkColumn. You can subscribe to the MouseLeftButtonUp event of the TextBlock element defined within the CellTemplate of the GridViewDataColumn and use a Style to imitate a hyperlink:

Declare the GridViewHyperlinkColumn and its CellTemplate:

    <Style x:Key="HyperlinkStyle" TargetType="TextBlock"> 
        <Setter Property="Foreground" Value="Blue" /> 
        <Setter Property="TextDecorations" Value="Underline" /> 
    </Style>                    ... 
   <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}"> 
                        <TextBlock Style="{StaticResource HyperlinkStyle}" Text="{Binding Name}" MouseLeftButtonUp="TextBlock_MouseLeftButtonUp"/> 

Handle the MouseLeftButtonUp event

    private void TextBlock_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) 
        var teamName = (e.Source as TextBlock).Text; 
The result will be the same as the one shown in Figure 2.

See Also

In this article