Link to home
Start Free TrialLog in
Avatar of bflow
bflowFlag for New Zealand

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


Avatar of Priest04
Priest04
Flag of Serbia image

I cant manifest this behaviour....

private void dateTimePicker1_Validating(object sender, CancelEventArgs e)
        {
            MessageBox.Show(dateTimePicker1.Value.ToString());
        }


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
ASKER CERTIFIED SOLUTION
Avatar of RubenvdLinden
RubenvdLinden

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bflow

ASKER

Great!

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.ValueChanged += new System.EventHandler(this.dateTimePicker1_ValueChanged);
           

 private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
 {
            MessageBox.Show("Value Changed");
 }