【发布时间】:2011-06-01 08:48:00
【问题描述】:
如何在DataGrid的行被编辑时捕获事件并从中获取所有值?
如果我使用 RowEditEnding 事件,我无法获取新值...
谢谢!
【问题讨论】:
标签: wpf visual-studio-2010 .net-4.0 datagrid
如何在DataGrid的行被编辑时捕获事件并从中获取所有值?
如果我使用 RowEditEnding 事件,我无法获取新值...
谢谢!
【问题讨论】:
标签: wpf visual-studio-2010 .net-4.0 datagrid
查看here的讨论,以及这个解决方案:
private void OnRowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
{
DataGrid dataGrid = sender as DataGrid;
if (e.EditAction == DataGridEditAction.Commit) {
ListCollectionView view = CollectionViewSource.GetDefaultView(dataGrid.ItemsSource) as ListCollectionView;
if (view.IsAddingNew || view.IsEditingItem) {
this.Dispatcher.BeginInvoke(new DispatcherOperationCallback(param =>
{
// This callback will be called after the CollectionView
// has pushed the changes back to the DataGrid.ItemSource.
// Write code here to save the data to the database.
return null;
}), DispatcherPriority.Background, new object[] { null });
}
}
}
【讨论】: