views:

322

answers:

2

I have a databound DateTimePicker:

dateDateTimePicker.DataBindings.Add(new Binding("Value", paymentBindingSource, "Date", true);
paymentBindingSource.DataSource = payment;

payment is Entity Framework object. payment.Date contains valid DateTime. When form is shown, dateDateTimePicker contains correct value, but an ErrorProvider is shown next to it, saying "Value of '01.01.0001 00:00:00' is not valid for 'Value'." It disappears when I change dateDateTimePicker value to anything.

A: 

Would it be possible to see your validation code? I am guessing the validation error occurs when you first load the form, and that the way you bind the data does not clear the (existing) validation error, while when you manually change the value, that is triggering the relevant code.

Ruffles
+1  A: 

Try reversing those two lines of code. The first line is probably looking to the data source, which, at that point, is null.

Jon Seigel