C# datetime validation problem

We have a Visual Studio 2010, C#, Windows application.

We have a custom form in the C# project which has a datetime control.
We are capturing the Validating event for this control.

The event appears to get fired correctly when the user attempts to leave the control.

If the user uses the mouse to select a new date, when inside the validation routine, the Value property is set to the newly selected value.

However, if the user uses the keyboard to enter a new date, when inside the validation routine, the Value property is still set to the previous value.

How do I get the Value property to have the correct value after the user changes the value with the keyboard? Or, what is the correct way to get the new value when inside the Validating event for the datetime control?

Thanks.



can you post the validation method ?



can you post the validation method ?



Sure. I've been able to recreate this in a new Windows project.
The validation snippet from the test project:
private void dtReqShipDate_Validating(object sender, CancelEventArgs e)
{
this.lblValidateValue.Text = this.dtReqShipDate.Value.ToString("M/d/yyyy");
}



are you firing this method when you click a button ?

please post the whole routine so I can see whats going on please



That is the whole method from my test project.

But, more info...
Inside the InitializeComponent() method:this.dtReqShipDate.Validating += new System.ComponentModel.CancelEventHandler(this.dtReqShipDate_Validating);

I've updated a zip file of the test form I used to recreate the issue.



I cannot reproduce the problem using the files from your zip. Is there something else that needs to occur.

What I tried:
Modified the date using the keyboard and tabbed out of the control. Label updates with new value.
Modified the date using the keyboard and moused out of the control. Label updates with new value.
Modified the date using the date dropdown and tabbed out of the control. Label updates with new value.
Modified the date using the date dropdown and moused out of the control. Label updates with new value.

-saige-

Share this

Related Posts

There was an error in this gadget