bflow
asked on
DateTimePicker validating event unreliable
I have a couple of datetimepicker fields on my form.
I need to simply validate if one date is less than the other.
Therefore on the validating event of the 2nd field I perform a check:
if Date2.Value < Date1.Value
This works fine if I the validation is as a result of a selection from the datetimepicker lookup.
But....
if the date is showing 05/06/2007 for example and the user enters 04/06/2007 i.e. just changes the 5 to 4 and tabs out of the field the value is still showing 05/06/2007.
If I then go back in to the field and change it again the value will then show 05/06/2007.
i.e. it's out of step.
Any ideas why this is happening and how to resolve it?
Brian
I need to simply validate if one date is less than the other.
Therefore on the validating event of the 2nd field I perform a check:
if Date2.Value < Date1.Value
This works fine if I the validation is as a result of a selection from the datetimepicker lookup.
But....
if the date is showing 05/06/2007 for example and the user enters 04/06/2007 i.e. just changes the 5 to 4 and tabs out of the field the value is still showing 05/06/2007.
If I then go back in to the field and change it again the value will then show 05/06/2007.
i.e. it's out of step.
Any ideas why this is happening and how to resolve it?
Brian
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great!
Saved a lot of time, making the field invisible and then visible again did the trick!
Thanks a lot.
Brian
Saved a lot of time, making the field invisible and then visible again did the trick!
Thanks a lot.
Brian
Hi,
Use the ValueChanged event instead of Validating
this.dateTimePicker1.Value Changed += new System.EventHandler(this.d ateTimePic ker1_Value Changed);
private void dateTimePicker1_ValueChang ed(object sender, EventArgs e)
{
MessageBox.Show("Value Changed");
}
Use the ValueChanged event instead of Validating
this.dateTimePicker1.Value
private void dateTimePicker1_ValueChang
{
MessageBox.Show("Value Changed");
}
private void dateTimePicker1_Validating
{
MessageBox.Show(dateTimePi
}
it will always show the same value as in DateTimePicker1, no matter if I select value, or enter if manually, or change it with KeyUp/Down
Goran