wRAR
wRAR

Reputation: 25693

Databound DateTimePicker fires validation error

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.

Upvotes: 1

Views: 1171

Answers (2)

Jon Seigel
Jon Seigel

Reputation: 12401

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

Upvotes: 1

Ruffles
Ruffles

Reputation: 79

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.

Upvotes: 0

Related Questions