I am trying to get the row index for the selected item in a data grid bound to a DataTable
.
Here is my attempt (based on this SO answer):
private void ShowRowIndex_Btn(object sender, RoutedEventArgs e)
{
int editedRowIndex = myDataGrid.Items.IndexOf(myDataGrid.CurrentItem);
MessageBox.Show(editedRowIndex.ToString());
}
<DataGrid CellEditEnding="PriceListDG_CellEditEnding" RowEditEnding="MyDataGrid_RowEditEnding" Name="priceListDataGrid" />
Unfortunately I always get -1 as the result.