Hi, I have a datagrid which has one hyperlink column with the following code:
<dg:DataGrid Style="{StaticResource DataGridStyle}" x:Name="movieGrid"
ItemsSource="{Binding ElementName=This, Path=movieData}">
<dg:DataGrid.ContextMenu>
<ContextMenu Name="cm">
<MenuItem Header="Copy" Click="CopyCell_Click"/>
</ContextMenu>
</dg:DataGrid.ContextMenu>
<dg:DataGrid.Columns>
<dg:DataGridTemplateColumn x:Name="editColumn" Width="40" Header="Edit" CanUserResize="False">
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="Edit" Height="20" Tag="{Binding Path}" Click="Edit_Click"/>
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>
<dg:DataGridTextColumn x:Name="titleColumn" IsReadOnly="True" Binding="{Binding Title}" Header="Title" SortDirection="ascending" />
<dg:DataGridTextColumn Visibility="Collapsed" x:Name="titleDiffColumn" IsReadOnly="True" Binding="{Binding IMDBTitle}" Header="IMDBTitle" />
<dg:DataGridTextColumn x:Name="scoreColumn" IsReadOnly="True" Width="60" Binding="{Binding Score}" Header="Score" />
<dg:DataGridTextColumn x:Name="yearColumn" IsReadOnly="True" Width="60" Binding="{Binding Year}" Header="Year" />
<dg:DataGridTextColumn x:Name="genreColumn" IsReadOnly="True" Binding="{Binding Genre}" Header="Genre" />
<dg:DataGridTemplateColumn x:Name="linkColumn" Width="195" Header="Link">
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Margin="3,0,0,0"><Hyperlink Tag="{Binding Link}" Click="Link_Click"><TextBlock Text="{Binding Link}"/></Hyperlink></TextBlock>
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>
<dg:DataGridCheckBoxColumn x:Name="seenColumn" Width="60" Binding="{Binding Seen}" Header="Seen"/>
</dg:DataGrid.Columns>
</dg:DataGrid>
As u can see i use a contextmenu on the cells to get their value, using the following code:
//copy datagrid item
private void CopyCell_Click(object sender, RoutedEventArgs e)
{
DataRowView itemsSource = movieGrid.CurrentItem as DataRowView;
int index = movieGrid.CurrentColumn.DisplayIndex;
string cellValue = itemsSource.Row.ItemArray[index - 1].ToString();
Clipboard.SetData(DataFormats.Text, cellValue);
}
This obviously doesn't work on the hyperlink column since it's a templatecolumn.
Is there a work arround to still get the link copied?
I tried with a context menu on the hyperlink itself but it didn't work, object references were wrong.
Thanks a bunch,
regards,
-WtFudgE-