用户编辑完行后如何获取DataGrid行数据?
我想在用户完成在数据网格中输入行后立即validation用户输入的内容。
我应该查看什么事件,以及如何检索行数据? 或者甚至更好,它必然会受到什么影响?
使用RowEditEnding事件。
private void DataGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e) { YourObject obj = e.Row.Item as YourObject; if (obj != null) { //see obj properties } }
- 事件RowEditEnding
- 数据应该在e.Row.DataContext / e.Row.Item中
如果您遇到问题,我成功使用:
DataGridCellInfo selected = YourDataGrid.SelectedCells[0]; YourObject selectedRow = selected.Item as YourObject;