DateTimePicker ValueChanged event repeats with month arrow

When the forward or back arrow is clicked on my DateTimePicker it repeatedly fires the ValueChanged event. I have to use a debugger to stop the application.

Note. My application is working fine while I click on one of the dates.

The MSDN documentation provides examples of creating a control. But I canโ€™t find any sample function called dateTimePicker1_ValueChanged (). The skeleton since this function was created for me when I double-clicked the control in the VS.NET2008 constructor.

+8
c #
source share
3 answers

Dave81 set me on the right track. If you do what he says, the problem is that when the user changes the value manually, the CloseUp event obviously does not fire. The way I fixed this problem with constantly re-triggering the month change event is to change the ValueChanged event only to update if the calendar does not fall. 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; ... } 
+3
source share

It is not clear to me what you are trying to achieve, but I assume that you want, for example, to show a message or something like that. If so, then there is no fear, because you are facing the same problem that I was interested in some time ago. Instead of using ValueChanged -event, use CloseUp -event. CloseUp -event is only triggered when the user finally selects a value. Hope this is what you were looking for. If you want to update, for example, some of the calculations shown to the user in the user interface, you should use ValueChanged -event.

+12
source share

When you click the down arrow datetimepicker, the default date is displayed. When you click on any date in the datetime collector, it fires the datetimepicker1_valuechanged event. Regardless of the fact that you put the skeleton for the event, it works great. Unnikrishnan c

+1
source share

All Articles