How do I Data-Bind dual DateTimePicker to a single DateTime object
Posted
by S.C. Madsen
on Stack Overflow
See other posts from Stack Overflow
or by S.C. Madsen
Published on 2010-04-27T18:04:56Z
Indexed on
2010/05/10
17:04 UTC
Read the original article
Hit count: 319
Hi,
I have a simple form, with two DateTimePicker-controls: One for date, and one for time. The thing is these two controls are supposed to represent a single point in time. Hence I would like to "Bind" them to a single DateTime property on my form (for simplicity). I did the following:
// Start is a DateTime property on the form
_StartDate.DataBindings.Add("Value", this, "Start");
_StartTime.DataBindings.Add("Value", this, "Start");
But hooking into "ValueChanged" event, yields mixed results... Sometimes I get exactly what I want, sometimes the updates of the property are "sluggish". I figured this way of splitting into two DateTimePicker's was fairly common. So how to do it?
Update: There is possibly multiple questions in there:
- How do I bind a DateTimePicker (Format: Date) to a DateTime Property on a form?
- Then, how do I bind yet another DateTimePicker (Format: Time) to the same property?
- I'm using Visual Studio Express 2008 (.NET 3.5), and I seemingly get ValueChanged events from the DateTimePickers before the value is changed?
© Stack Overflow or respective owner