How to get DataGrid row data after user has finished editing row?

妖精的绣舞 提交于 2019-12-07 18:10:40

问题


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?


回答1:


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
  }
}



回答2:


  1. Event RowEditEnding
  2. Data should be in e.Row.DataContext/e.Row.Item



回答3:


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

DataGridCellInfo selected = YourDataGrid.SelectedCells[0];
YourObject selectedRow = selected.Item as YourObject; 


来源:https://stackoverflow.com/questions/4674048/how-to-get-datagrid-row-data-after-user-has-finished-editing-row

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!