WPF DataGrid Get Current Row

Data Grid – Get Current Row. E.g. For Jump to Details – Data Grid Button Click

<DataGrid.Columns>
<DataGridTemplateColumn Header="Details" Width="80">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button x:Name="JumpButtonColumn" Content="{Binding Path=AdviceNoteNo}" Click="JumpButtonColumn_Click"></Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>>

And the Code

private void JumpButtonColumn_Click(object sender, RoutedEventArgs e)
{
if (invoiceDataGrid.CurrentColumn != null && invoiceDataGrid.CurrentColumn.DisplayIndex == 0)
{
Invoice myInvoice = ((FrameworkElement)sender).DataContext as Invoice;
Jump(myInvoice.InvoiceNo);
}
};

or

Private Sub JumpButtonColumn_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
   If AdviceNoteDataGrid.CurrentColumn IsNot Nothing AndAlso AdviceNoteDataGrid.CurrentColumn.DisplayIndex = 0 Then
       Dim myAdviceNote As AdviceNote = CType((CType(sender, FrameworkElement)).DataContext, AdviceNote)
       Jump(myAdviceNote.AdviceNoteNo)
   End If
End Sub

End

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: