BUG? : Databinding To DateObject Returning Invalid Date

  • Thread starter Thread starter Marauderz
  • Start date Start date
M

Marauderz

Hi, I have an object that implements IEditableObject that exposes a Date
property.

A DateTimePicker on a form is bound to the property on the object.

But when I call BindingContext.CancelCurrentEdit on it I get an error that
says I'm trying to set an invalid date to the control a date of 01/01/0001
12:00:00AM.

Obviously something's wrong, I've stepped through the CancelEdit call on my
object, the member variables all have proper dates so I don't know how this
came to be, any suggestions?

Thanks!
 
OK, I found the problem..

It seems like at least in 1.0 of the framework, when you Databind to a
control which is NOT visible. Databinding screws up bad. Can anyone confirm
this? I already have seen this exhibited in Labels, and DateTimePickers.
 
Marauderz,

With out knowing what is going on under the hood it's difficult for me to say for sure. This property that you are binding too seems to have a valid date but I don't think the calendar control allows dates only one year after AD. When you initialize the date variable try putting a date in it as a test.

Dim Mydate as DateTime = Now


-Calvin Luttrell
ProjectThunder.com
 
My gut feeling on this is that your control has code to initialize the date
and time when the control is drawn, hence the reason binding to it invisible
doesn't work. .NET usually has not problem binding to 'controls' which are
not visible providing the control's are written properly. I'm not at all
being funny here, but when I'm stuck with a problem like this one I usually
ending reading the error message very very slowly and literally. In your
case, that indicates an invalid date so check the code in the control is
initializing the date without requiring the control to be drawn.

Hope that helps some,
 
Back
Top