Facts:
Why this happen? How can I avoid it?
I found out what the problem was here.
The Value
property only sets a new value if the DateTimePicker
control is visible. Otherwise command is ignored.
Test case:
Doesn't work:
this.picker = new DateTimePicker
{
Checked = false,
Font = new System.Drawing.Font("Verdana", 9.75F),
Format = System.Windows.Forms.DateTimePickerFormat.Time,
Location = new System.Drawing.Point(5, 5),
Name = "picker",
ShowUpDown = true,
Size = new System.Drawing.Size(120, 23),
Visible = false
};
this.Controls.Add(this.picker);
this.picker.Value = this.picker.Value.Date.AddHours(1);
this.picker.Visible = true;
Works:
this.picker = new DateTimePicker
{
Checked = false,
Font = new System.Drawing.Font("Verdana", 9.75F),
Format = System.Windows.Forms.DateTimePickerFormat.Time,
Location = new System.Drawing.Point(5, 5),
Name = "picker",
ShowUpDown = true,
Size = new System.Drawing.Size(120, 23),
Visible = false
};
this.Controls.Add(this.picker);
this.picker.Visible = true;
this.picker.Value = this.picker.Value.Date.AddHours(1);
Doesn't appear to have anything to do with programatically adding the picker it seems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With