Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Datagrid Row Validation

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.

like image 840
user1864953 Avatar asked Dec 21 '12 18:12

user1864953


1 Answers

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.

like image 67
Sankarann Avatar answered Sep 25 '22 08:09

Sankarann