When the month forward or backward arrow is clicked on my DateTimePicker control it repeatedly fires the ValueChanged event. I have to use the debugger to stop the application.
Note: My application works fine as long as I click on one of the dates.
The MSDN documentation shows examples for creating the control. But I cannot find any example function called dateTimePicker1_ValueChanged(). The skeleton for this function was created for me, when I double clicked on the control in the VS.NET2008 designer.
In Windows Forms, the DateTimePicker control is used to select and display the date/time with a specific format in your form.
The DateTimePicker control is used to allow the user to select a date and time, and to display that date and time in the specified format.
You can set the current date value in DateTimePickerAdv by disabling the IsNullDate property and set the DateTimePickerAdv value as current date.
The DateTimePicker control allows you to display and collect date and time from the user with a specified format. The DateTimePicker control has two parts, a label that displays the selected date and a popup calendar that allows users to select a new date.
It is not clear to me what you are trying to achieve but my guess is that you want for example show a messagebox or something similar. If so then no fears because you are facing the very same issue I was wondering some time ago. Instead of using the ValueChanged -event, use the CloseUp -event. CloseUp -event is triggered only when the user finally selects a value. Hope this was what you were looking for. If would want to update for example some calculations shown to user in the UI you would use ValueChanged -event.
Dave81 set me on to the right track. If you do what he says, the problem is, that when the user changes the value manually, the CloseUp event obviously isn't triggered. The way I've fixed this problem with the constant re-firing of the month change event, is to change my ValueChanged event to only refresh if the calendar isn't dropped down. I.e.:
private bool _calendarDroppedDown = false;
//called when calendar drops down
private void dateStartDateTimePicker_DropDown(object sender, EventArgs e)
{
_calendarDroppedDown = true;
}
//called when calendar closes
private void dateStartDateTimePicker_CloseUp(object sender, EventArgs e)
{
_calendarDroppedDown = false;
RefreshToolbox(null, null); //NOW we want to refresh display
}
//This method is called when ValueChanged is fired
public void RefreshToolbox(object sender, EventArgs e)
{
if(_calendarDroppedDown) //only refresh the display once user has chosen a date from the calendar, not while they're paging through the days.
return;
...
}
When you click on the down arrow of a datetimepicker, it displays a default date. When you click on any date in the datetime picker, it fires the datetimepicker1_valuechanged event. Whatever you have put the skeleton for the event, works fine then. Unnikrishnan C
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With