ValueChanged event of the DateTimePicker control is not raised when you change the date (822498)



The information in this article applies to:

  • Microsoft Visual Basic .NET (2003)
  • Microsoft Visual Basic .NET (2002)
  • Microsoft Visual C# .NET (2003)
  • Microsoft Visual C# .NET (2002)

SYMPTOMS

You set the date format and language in the regional settings on your computer and then add a DateTimePicker control to a Windows form. When you run the application and type a single digit in the date field of the DateTimePicker control, the ValueChanged event is not raised. The ValueChanged event of the control is raised only after you type any one of the following:
  • All the digits of a year.
  • All the digits of a day.
  • All the digits of a month.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce the Behavior

To set regional settings on your computer:
  1. In Control Panel, double-click Regional and Language Options.
  2. On the Regional Options tab, select English (United States) from the list, and then click Customize.
  3. In the Customize Regional Options dialog box, click the Date tab.
  4. In the Short date format list under Short date, select yyyy-MM-dd, and then click OK.
  5. In the Regional and Language Options dialog box, click OK.
  6. Start Microsoft Visual Studio .NET.
  7. Create a new Windows Application project by using Visual Basic .NET or Visual C# .NET. By default, Form1 is created.
  8. Add a DateTimePicker control to Form1.
  9. On Form1, right-click DateTimePicker1, and then click Properties.
  10. In the Properties dialog box, set the Format property to Short.
  11. Add the following code to the DateTimePicker1_ValueChanged event handler:

    Visual Basic .NET Code
     'The event is raised when the value is changed.
    System.Windows.Forms.MessageBox.Show("Value Changed")
    Visual C# .NET Code
    //The event is raised when the value is changed.
    System.Windows.Forms.MessageBox.Show("Value Changed");
  12. On the Build menu, click Build Solution.
  13. On the Debug menu, click Start.
  14. Type any date in the DateTimePicker1 control. The event is raised only after you enter 4 digits for a year, 2 digits for a month, or 2 digits for a day.

REFERENCES

For more information, visit the following Microsoft Developer Network (MSDN) Web site:

Modification Type:MinorLast Reviewed:2/9/2006
Keywords:kbvs2005doesnotapply kbvs2005swept kbEvent kbDateTime kbCtrl kbControl kbprb KB822498 kbAudDeveloper