DateTimePicker value changes while 'browsing' dates

Posted on 2010-03-24
Medium Priority
Last Modified: 2013-11-06

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!
Question by:postsuave
LVL 11

Expert Comment

ID: 28466874
You can use validating event

Expert Comment

by:Coralie Crumrine
ID: 28468189
Have you tried the LostFocus event?

Author Comment

ID: 28469309
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?
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

LVL 12

Expert Comment

ID: 28470044
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
LVL 12

Expert Comment

ID: 28470234
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

Accepted Solution

postsuave earned 0 total points
ID: 28470962
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


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
This article describes and provides a custom-made tool I wrote to give businesses a means of identifying commercial music content, without having to expend too much effort. Business recordings are easily identified from possibly illegal music files …
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question