DateTimePicker never updates!

У меня есть несколько DateTimePicker в форме, которая никогда не обновляется.
Я пробовал Value и Text , Invalidate () , а затем Update () , а также Refresh () ...

Похоже, что ничего не меняет свои значения по сравнению с текущей датой!
Независимо от того, что я установил, текущие даты (относительно) сегодняшние!

Это ошибка .NET 3.5 или что?
(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

13
задан Jon Seigel 14 November 2010 в 19:39
поделиться