Databinding DateTimePicker

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
 
I

Ilya Tumanov [MS]

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.
 
G

Guest

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top