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() 
    { 
        InitializeComponent(); 
        this.AddHandler(Hyperlink.ClickEvent, new RoutedEventHandler(hyperlinkClicked)); 
    } 
 
    private void hyperlinkClicked(object sender, RoutedEventArgs e) 
    { 
        Hyperlink hyperLink = e.OriginalSource as Hyperlink; 
        MessageBox.Show(hyperLink.NavigateUri.ToString()); 
    } 
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}"> 
                <telerik:GridViewDataColumn.CellTemplate> 
                    <DataTemplate> 
                        <TextBlock Style="{StaticResource HyperlinkStyle}" Text="{Binding Name}" MouseLeftButtonUp="TextBlock_MouseLeftButtonUp"/> 
                    </DataTemplate> 
                </telerik:GridViewDataColumn.CellTemplate> 
   </telerik:GridViewDataColumn> 

Handle the MouseLeftButtonUp event

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

See Also

In this article