10
votes

There seems to be a bug in WPF 4.0 DataGrids.

I'm implementing IDataErrorInfo on my objects, and I have an ObservableCollection that a datagrid binds to. I have ValidatesOnDataErrors=True set on the columns but nothing set on the rows. I have UpdateSourceTrigger="PropertyChanged"

The validation works perfectly on a cell by cell level. However, when you leave a cell invalid, go to any other cell and then return to the invalid cell and enter in valid data, the cell becomes valid but the row remains invalid when it should be valid.

2
I have the exact same problem!Reilly
Tree guys, same wpf issue and none posted code yet. That would be bad title for a movie anyway. :D Has anyone of you thought to post some code or xaml?dev hedgehog
Have you tried it with INotifyDataErrorInfo? As far as I know this interface is the recommended way of notifying about validation errors.Benjamin
My "super" solution was to turn off row validation because it is enough to have cell validation only and there is no any ambiguous behavior.SKINDER
While property change of that changed cell leads to get the HasError of IDataErrorInfo?Sankarann

2 Answers

4
votes

In general property validation, it will be validated once the source gets updated but in the case of a RowValidation you need to specify the RowValidationRule to perform the RowValidation.

 <DataGrid.RowValidationRules>
       <DataErrorValidationRule ValidatesOnTargetUpdated="True" ValidationStep="UpdatedValue" />
 </DataGrid.RowValidationRules>

Now the DataGrid will validates for the Rows also you can provide the RowValidationErrorTemplate to show the Error in Custom format.

0
votes

Had the same issue. The fix for me was setting ValidatesOnTargetUpdated="True" on the validation rule, which seems to force another validation every time the control gets updated.