Note that there are some explanatory texts on larger screens.

plurals
  1. PODateTimePicker never updates!
    text
    copied!<p>I have some <code>DateTimePicker</code>s in a form that never update.<br> I've tried <code>Value</code> and <code>Text</code>, <code>Invalidate()</code> and then <code>Update()</code> and also <code>Refresh()</code>... </p> <p>Nothing seems to change their values from the current date!<br> No matter what I set, the current dates are (relatively)today's! </p> <p>Is this a .NET 3.5 bug or what?<br> (No, I cannot use .NET 4 on this project.)</p> <hr> <p>If you really want some code, then here it is: <code>dateTimePicker1.Value = user.BirthDay;</code>. Also, if I write <code>MessageBox.Show(user.BirthDay.ToString());</code> I get a nice box telling the user's birthday (my birthday, on my machine). (So there is a value in the variable...)</p> <hr> <p>Should I also mention that they are only for dates and not times?</p> <hr> <p>Ok, I see I need to write more: </p> <p>First of all, the method in which the control is updated is subscribed to the <code>Form.Load</code> event. Consequently, it is called/fired/invoked when the form and the controls are visible and "running". </p> <p>Secondly, look at this pieces of code and their result:</p> <pre><code>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! </code></pre> <p>That's not nice... The output is today's date. (By today I mean the day in which the code was ran.) </p> <pre><code>dateTimePicker1.MinDate = new DateTime(1900,1,1); // January 1st, 1900 MessageBox.Show(dateTimePicker1.MinDate.ToString()); // January 1st, 1753 ... </code></pre> <p>Bad control! 1900 doesn't equal to 1753!</p> <pre><code>dateTimePicker1.MaxDate = DateTime.Today; // In reality, I need it to today's date MessageBox.Show(dateTimePicker1.MinDate.ToString()); // December 31st, 9998 </code></pre> <p>Time warp? O_O </p> <p>Anyway, the whole code looks like this:</p> <pre><code>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 } </code></pre> <p>So, any solution? xC</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload