Doubt regarding DateTimePicker

I have used a DateTimePicker in a windows form. I have also defined its ValueChanged event. Following is the event:

private
void dateTimePicker1_ValueChanged(object sender, System.EventArgs e)
{
if(dateTimePicker1.Value > DateTime.Today)
{
MessageBox.Show("Error");
}
}

I have many ways to change the date in the DateTimePicker like changing it manually or increasing the year, etc. But when I try to increment the month, using the arrow provided on the DateTimePicker to increment/decrement the month, the event is fired continuously (and not once) and I get the MessageBox recurringly. This is because the month goes on increasing (i.e. if the current month is Novemeber, the month changes to December, January, February and so on.).
Ideally, the MessageBox should have popped up only once.

Now, if I remove the MessageBox from the event, and leave the event blank, the month increases only by one if I click on the month increment/decrement button (i.e. if the current month is November, then it changes to December and stops)

Can someone explain this to me?

Regards,
Asim.

[1379 byte] By [Asim] at [2007-12-22]
# 1
The MessageBox is preventing the DataTimePicker from seeing the MouseUp event and it thinks the user is still holding the mouse button down and continues to increment the month.

If you want to validate the DateTimePicker date, have a look at the Validating event.

DavidM.Kean at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 2
Hi,
Thanks for your reply. But I still haven't been able to resolve the problem. The requirement is that I should check for the date the very moment it changes and if the date is a valid one, I need to go to the database to fetch some data. Validating event will only occur when is move the focus out of the DateTimePicker.

I know one work around would be to have a button on click of which I should validate the date and then go the database.
But is it possible without using another button?

Regards,
Asim.

Asim at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 3

Simply don't display the MessageBox in the ValueChanged event. Perhaps use an ErrorProvider to display an error if the date can not be found.

DavidM.Kean at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 4

I have the same problem. Other logic of a form I am developing depends on the current value of the date and the validating event is not adequate for this.

After the value of the date time picker changes using the month button, it continues to scroll if a message box is shown as a result of it's ValueChanged event.

Does anyone know if Microsoft is fixing this bug? Did you find a suitable workaround, e.g. is there a way to simulate a mouse up event on the 'month scroll' buttons of the date time picker?

chisanga at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 5
David's solution of using the validating event worked out for me, but I would also like to know whether MS has addressed this bug. It seems to be a rather serious problem as it completely locks up a program and one is forced to terminate the process, which is really not good.
Jeremy613 at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms General...