【问题标题】:Catch RowEdited event in DataGrid WPF在 DataGrid WPF 中捕获 RowEdited 事件
【发布时间】:2011-06-01 08:48:00
【问题描述】:

如何在DataGrid的行被编辑时捕获事件并从中获取所有值?

如果我使用 RowEditEnding 事件,我无法获取新值...

谢谢!

【问题讨论】:

    标签: wpf visual-studio-2010 .net-4.0 datagrid


    【解决方案1】:

    查看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 });
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2014-07-15
      • 2013-11-13
      • 1970-01-01
      • 2020-05-08
      • 2012-05-10
      • 1970-01-01
      • 2011-07-24
      • 2016-03-31
      • 2019-08-10
      相关资源
      最近更新 更多