Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

DataGrid exception on validation failure (DeferRefresh is not allowed...)

$
0
0

In the same series as the DataGrid validation scheme issues , I get an exception when

  • a cell is invalid
  • the DataContext changes

This happens in a DataGrid, which is bound to a CollectionViewSource. This CVS itself has a DataContext bound to the currently selected product of a ListBox. So we are editing the details of product, those details include a data list in a DataGrid (DataGridTextColumn in this case).

Either by using a data type that implements IDataErrorInfo or by using a ValidationRule, if the validation fails the DataGrid reacts by keeping the TextBox and showing a red box around it (when the validation is OK, the cell is tranformed back to a TextBlock).

Nothing prevents me from selecting another product. The DataGrid then shows the new data and everything is fine. But if I come back to the product which failed validation, I get this exception:

InvalidOperationException, 'DeferRefresh' is not allowed during an AddNew or EditItem transaction .

How can I prevent that? What is the correct way of cancelling the edit on that faulty cell when another product is selected, or when the DataContext changes?

I can detect those events, but CancelEdit() doesn't work on the DataGrid (no result).

I'm using .NET 4.

 

The code can be viewed here: C# part ,XAML part . The code can be downloadedfrom here .


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>