Answered by:
DateTimePicker: Preventing Value change event when switching months in the pop-up calendar?

Question
-
Hi,
I was wondering if anyone knew how to know when the user is clicking on an actual date or on the arrows that switch between months in the pop-up calendar. Or if there is a way to prevent the ValueChanged event from firing when the arrows are clicked. I'm trying to design an application that uses a lot of DateTimePickers and where I update the dates through code. I'm trying to figure out how to catch when the USER is actually selecting the date.
Thanks for your help,
DarkAraym
Friday, March 7, 2008 9:33 PM
Answers
-
Hi,
You can use the MonthCalendar control instead, it has two different event: DateChanged event and DateSelected event; when navigating with arrows on the title, only DateChanged event is fired, and the DateSelected event is fired when a date is actually selected. To show a MonthCalendar in dropdown style, you can check my sample in this thread
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2435605&SiteID=1
Best Regards,
Zhi-xin Ye.Wednesday, March 12, 2008 12:07 PM
All replies
-
Saturday, March 8, 2008 2:36 AM
-
Thanks for your response, but can you please explain what you mean by removing the handler with the -= syntax? I haven't encountered this before.
Thanks.
Monday, March 10, 2008 2:04 PM -
Maybe if i explain the situation a little better, it might be easier to understand what i'm tryin to accomplish.
First I forgot to mention that i'm using VB.NET in VS2005.
This application is connected to a SQL DB and I can't give a datepicker a null value(and i don't want to try), so what the user sees is a textbox which displays the date and right next to it is the datepicker. But they only see the box with the arrow part of the date picker. This forces the user to use the drop down calendar when selecting dates. I have code setup that when the value of the datepicker is changed, the date is posted to the textbox.
This at the same time causes my issue. If the user opens the drop down calendar and moves forward/backward a month using the arrows in the drop down calendar(which causes the value of the datepicker to change) and then closes the drop down calendar. Obviously the user never clicked on a specific date but because the value was changed it is posted to the textbox.
I need to figure out a way to identify the difference between selecting a specific date and moving between months. Using this I can define when to post the date to the textbox.
Thanks.
Monday, March 10, 2008 5:11 PM -
Hi,
You can use the MonthCalendar control instead, it has two different event: DateChanged event and DateSelected event; when navigating with arrows on the title, only DateChanged event is fired, and the DateSelected event is fired when a date is actually selected. To show a MonthCalendar in dropdown style, you can check my sample in this thread
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2435605&SiteID=1
Best Regards,
Zhi-xin Ye.Wednesday, March 12, 2008 12:07 PM -
Hi,
You can handle this three events : ValueChanged, CloseUp and DropDown .
ValueChanged occurs when the value changes directly in the box are on the calendar. To preventh change of the date when switching months remove ValueChanged event handler (e.g.....ValueChanged -= new EventHandler...) when the calender opens in DropDown eventHandler. When Calender is closed in CloseUp eventHandler set back ValueChanged eventhandler and call the methos that handles the change of that event.
bye
- Proposed as answer by koenmetsu Friday, June 7, 2013 11:50 AM
Monday, May 12, 2008 12:23 PM