Databinding DateTimePicker

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to bind a DataTimePicker control to a DataSet but cant seem to
get it working. I am using the following code...

DateTimePicker.DataBindings.Add(New Binding("Value", dtSampleData, "Date"))

All of my other fields bind fine but when I try to bind the DateTimePicker
control I get 'Error 13 InvalidCastException'. I am binding to a Date field
that is a Date/Time datatype. Is binding the DateTimePicker even possible?
If so I would greatly appreciate any suggestions!

Thx
Mike
 
Yes, but you have to take care of handing null values in the DataSet as DTP
would not accept them.
To do so you need to implement Binding.Format Event handler. There's a
sample in VS documentation on how to do it.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Mike,

I've found that i always get errors when trying to bind to the "value"
property but can bind to the "text" property just fine.

Carl
 
Thanks Carl,

Well, at least that didnt fire an error when loading. But, it still is not
"bound". In other words, when I navigate between my records all of my other
bound controls change. My DateTimePicker just stays at the same value?

Mike
 
Back
Top