How to get DataGrid row data after user has finish

2019-05-11 12:55发布

I want to validate what the user has entered immediately after the user has finished entering a row in a datagrid.

What event should I be looking at, and how do I retrieve the row data? Or even better, the object it's bound to?

3条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-05-11 13:26

Use the RowEditEnding event.

private void DataGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
{
  YourObject obj = e.Row.Item as YourObject;
  if (obj != null)
  {
     //see obj properties
  }
}
查看更多
仙女界的扛把子
3楼-- · 2019-05-11 13:31
  1. Event RowEditEnding
  2. Data should be in e.Row.DataContext/e.Row.Item
查看更多
欢心
4楼-- · 2019-05-11 13:33

If you're having problems, I had success using:

DataGridCellInfo selected = YourDataGrid.SelectedCells[0];
YourObject selectedRow = selected.Item as YourObject; 
查看更多
登录 后发表回答