我正在尝试获取绑定(bind)到 DataTable
的数据网格中所选项目的行索引。
这是我的尝试(基于 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" />
不幸的是,我总是得到 -1 作为结果。
最佳答案
如果你想获取当前正在编辑的行的索引,你可以直接在你的 RowEditEnding
事件中进行:
private void OnRowEditEnding(object sender, .DataGridRowEditEndingEventArgs e)
{
var index = e.Row.GetIndex();
}
关于c# - 获取数据网格中所选项目的行索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53388800/