开发者

Catch RowEdited event in DataGrid WPF

开发者 https://www.devze.com 2023-03-09 21:52 出处:网络
How to catch event when DataGrid\'s row was edite开发者_运维问答d and get all values from it? If I use RowEditEnding event, I can\'t get new values...

How to catch event when DataGrid's row was edite开发者_运维问答d and get all values from it?

If I use RowEditEnding event, I can't get new values...

Thanks!


See the discussion here, and this solution:

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 });
        }
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消