I have some DateTimePicker
s in a form that never update.
I've tried Value
and Text
, Invalidate()
and then Update()
and also Refresh()
...
Nothing seems to change their values from the current date!
No matter what I set, the current dates are (relatively)today's!
Is this a .NET 3.5 bug or what?
(No, I cannot use .NET 4 on this project.)
If you really want some code, then here it is: dateTimePicker1.Value = user.BirthDay;
. Also, if I write MessageBox.Show(user.BirthDay.ToString());
I get a nice box telling the user's birthday (my birthday, on my machine). (So there is a value in the variable...)
Should I also mention that they are only for dates and not times?
Ok, I see I need to write more:
First of all, the method in which the control is updated is subscribed to the Form.Load
event. Consequently, it is called/fired/invoked when the form and the controls are visible and "running".
Secondly, look at this pieces of code and their result:
MessageBox.Show(user.BirthDay.ToString()); // Shows 12.12.1995 (in my regional format)
dateTimePicker1.Value = user.BirthDay; // assigned to 12.12.1995
MessageBox.Show(dateTimePicker1.Value.ToString()); // Shows today's date!
That's not nice... The output is today's date. (By today I mean the day in which the code was ran.)
dateTimePicker1.MinDate = new DateTime(1900,1,1); // January 1st, 1900
MessageBox.Show(dateTimePicker1.MinDate.ToString()); // January 1st, 1753 ...
Bad control! 1900 doesn't equal to 1753!
dateTimePicker1.MaxDate = DateTime.Today;
// In reality, I need it to today's date
MessageBox.Show(dateTimePicker1.MinDate.ToString()); // December 31st, 9998
Time warp? O_O
Anyway, the whole code looks like this:
public void Form_Load(object sender, EventArgs e)
{
this.user = User.Load(path);
// this.user is a field.
// path is a static field which holds the absolute path of the file in which is serialized that data of the user.
MessageBox.Show(user.BirthDay.ToString()); // Shows 12.12.1995 (in my regional format)
dateTimePicker1.Value = user.BirthDay; // assigned to 12.12.1995
MessageBox.Show(dateTimePicker1.Value.ToString()); // Shows today's date!
dateTimePicker1.MinDate = new DateTime(1900,1,1); // January 1st, 1900
MessageBox.Show(dateTimePicker1.MinDate.ToString()); // January 1st, 1753 ...
dateTimePicker1.MaxDate = DateTime.Today;
MessageBox.Show(dateTimePicker1.MinDate.ToString()); // December 31st, 9998
}
So, any solution? xC
The JavaScript DateTime Picker is a lightweight and mobile-friendly control that allows end users to enter or select date and time values from a pop-up calendar and drop-down time list. It provides month, year, and decade views for quick navigation to the desired date.
The DateTimePicker control is used to allow the user to select a date and time, and to display that date and time in the specified format. The DateTimePicker control makes it easy to work with dates and times because it handles a lot of the data validation automatically.
In Windows Forms, the DateTimePicker control is used to select and display the date/time with a specific format in your form.
One small hint with this trouble: my problem was that I had the DateTimePicker set to checked=false and (by mistake) ShowCheckbox=false; With this setup I could set to DTPicker whatever value I wanted, but it won't udate itself.
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