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
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: The result after clicking the hyperlink
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);
}