10

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.

Tim M.
  • 53,671
  • 14
  • 120
  • 163
user1864953
  • 101
  • 1
  • 3
  • I have the exact same problem! – Reilly Dec 27 '12 at 18:51
  • "However, when you leave a cell invalid, go to any other cell and then return to the invalid cell and enter a valid data, the cell becomes valid but the row remains invalid when it should be valid." Exactly the same problem. – SKINDER Oct 10 '13 at 12:23
  • 1
    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 Oct 15 '13 at 20:21
  • 3
    Have you tried it with `INotifyDataErrorInfo`? As far as I know this interface is the recommended way of notifying about validation errors. – Benjamin Oct 16 '13 at 15:45
  • 5
    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 Oct 17 '13 at 12:07
  • 1
    While property change of that changed cell leads to get the HasError of IDataErrorInfo? – Sankarann Nov 01 '13 at 06:19
  • Can you share with us a part of your XAML please ? – SomeCode.NET Dec 12 '14 at 10:16
  • Possible duplicate of [WPF DataGrid validation errors not clearing](http://stackoverflow.com/questions/5099039/wpf-datagrid-validation-errors-not-clearing) – Athafoud Aug 03 '16 at 06:53

2 Answers2

4

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.

Sankarann
  • 2,625
  • 4
  • 22
  • 59
1

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.

slimbofat
  • 391
  • 2
  • 7