0
votes

I have a DataGrid and canUserAddRows=true and an ObservableCollection. I want something like a validation for the ObservableCollection. So user add a row and before it gets to the ObservableCollection, I want to check the data...

I have tried RowEditEnding-Event, but when this event is fired, the new row isn't add to the ObservableCollection at this time.

Another try is the CollectionChanged-Event fromt the ObservableCollection itself but for some reason this doesn't fire... I know I could use a validation for DataBinding but there should be a way over events, or?

I am using .NET 3.5 and WPF.

Thank you in advance.

1
It becomes very straight forward if your objects inherit from IEditableObject.Gayot Fow

1 Answers

0
votes

There are several different ways to perform data validation when using WPF. None of them are particularly quick to implement. I personally tend to prefer implementing either the IDataErrorInfo or INotifyDataErrorInfo interfaces on my data items.

You can also use the ValidationRule class on your Bindings. However, for a complete validation example with the DataGrid, you can also refer to the How to: Implement Validation with the DataGrid Control page on MSDN.