开发者

Catch RowEdited event in DataGrid WPF

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜