Поймать событие RowEdited в DataGrid WPF - PullRequest
0 голосов
/ 01 июня 2011

Как перехватить событие, когда строка DataGrid была отредактирована, и получить из нее все значения?

Если я использую событие RowEditEnding, я не могу получить новые значения ...

Спасибо!

1 Ответ

0 голосов
/ 20 января 2012

Смотрите обсуждение здесь , и это решение:

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 });
        }
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...