开发者

DateTimePicker ValueChanged event fires the first time when there is no change

Winforms 2.0. Stick a DateTimePicker on a form. It开发者_JS百科 defaults to TODAY. Click on the dropdown arrow to show the Calendar, and click on TODAY. The ValueChanged event DOES FIRE, even though it is already set to today.

What i would like to do is replicate this same functionality - I would like to reset it (in code) to today, and next time i click on today via the Calendar i want that ValueChanged event to fire (just like it did the first time).

If the above is not possible, i want some event that always fires whenever i pick a date on the Calendar (regardless if there is a change or no change).

Sounds really simple, surely someone has the answer?


What you're seeing there is a side-effect of the fact that DateTimePicker stores the time component of its value as well as the date.

So when your form first initializes, the DateTimePicker is being initialized with DateTime.Now. When you then select "Today" from its drop-down calendar, you're changing the value to DateTime.Today.

If you don't care about the time component and/or you're always reading the value as dateTimePicker1.Value.Date, then you could initialize the control in code with DateTime.Now and the ValueChanged event will fire when the user selects Today from the calendar. Otherwise you might consider catching the CloseUp event, which is fired whenever the calendar control is closed (regardless of whether the value changed).


Im not a win form programmer, but see if there is a Day_Render event. That should fire for each day...at least there is one for web based development, but I would think it is the same. So look for Render() event.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜