DateTimePicker value changes while 'browsing' dates


i have a windows form application that uses a datetime picker to select a date. I use the valuechanged event to see wether another date is selected > that fires a long and complex procedure that sets up the screen with data for that date...

now here's my problem:
because it takes some time to 'load' another date, i want to do that only when a user has selected a date. The valuechanged event fires also when you click on the arrowbuttons to move up or down a month.

to make it even more clear this example:
- the control has value 2010-03-24
- user wants it to have value 2009-09-01
- user clicks 6 times on the 'move down month' button
- user clicks on day1.

my 'load screen' procedure gets fired 7 times, but i want it to fire only when the user deliberately selects a final date.

i tried several events, including the leave, mouseup, validated, textchanged events, but didn't manage to achieve the goal.

of course i know that i can place a 'GO' button besides the control, but i don't want that...

Thanks for any help!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can use validating event
Coralie CrumrineCommented:
Have you tried the LostFocus event?
postsuaveAuthor Commented:
lostfocus event is no good because after a date is deliberately selected, the control remains focussed.

the validating event occurs just before the valuechanged event so how would that help?
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

GMGeniusSoftware Development Manager/DeveloperCommented:
If you dont want to fire the event when changing month or year and only when the users selects a day then I would suggest you record the previous value of the date picker and ignore the event if the month only or year only changes.

Effectively only fire on the day change.

The only drawback would be if they did want the same day in another month/year
GMGeniusSoftware Development Manager/DeveloperCommented:
Or another idea would be to use a timer

When the event fires start the timer, each time the event fires it would restart the timer, then you update code could go in the timer tick event instead
postsuaveAuthor Commented:
tried the timer thing months ago, but the problem is that the software is used on about 200 computers with all different speeds... it caused me nothing but troubles...

i just found a solution myself, i'll include the code if anyone else ever might have the same problem...
it' s a combination of the CloseUp event and the KeyUp event, for up and down arrow key.

thanks for all effort anyway!
    Private Sub dt_CloseUp(ByVal sender As Object, ByVal e As System.EventArgs) Handles dt.CloseUp
        Call changeactivedate()
    End Sub

    Private Sub dt_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dt.KeyUp
        If e.KeyCode = Keys.Up Or e.KeyCode = Keys.Down Then
            Call changeactivedate()
        End If
    End Sub
    Sub changeactivedate()
        Me.Cursor = Cursors.WaitCursor
        Static previousdate As Date
        If previousdate = dt.Value Then Exit Sub
        previousdate = dt.Value
        Call LONGPROCEDURE()
        Me.Cursor = Cursors.Default
    End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.