Date Time Picker + Add Days

I have a date time picker on my windows form. I want to be able to add and subtract days to this without actually going to the calender part. I need to know how to capture the key up or key down event while the date time picker is selected.  I want to be able to add or subtract days (depending on which key is pressed the up arrow or the down arrow).  How do I do this?
LVL 4
computerg33kAsked:
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.

armoghanCommented:
Not fully understood, This example may help
http://www.codeproject.com/cs/miscctrl/cstimepicker.asp
0
ahmadfuwadCommented:
'try following code it will work fine

   Dim objdate As DateTime
        objdate = Me.DateTimePicker1.Text
        Me.TextBox1.Text = objdate.AddDays(7)
0
computerg33kAuthor Commented:
"I want to be able to add or subtract days (depending on which key is pressed the up arrow or the down arrow)"  ie(when the user selects the datetimepicker and presses the up arrow on the keyboard the day goes from 11/19/2004 to 11/20/2004 and when the user selects the datetimepicker and presses the down arrow on the keyboard the day goes from 11/20/2004 to 11/19/2004).  Neither answer is what i was looking for--sorry
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

armoghanCommented:
If you are talking about System.Windows.Forms.DateTimePicker. It already has this functionlity. Just place a DateTimePicker or an empty form and focus the date portion and it will role up or down on up down keys. Same is true for month/years ect
0
computerg33kAuthor Commented:
got it..
    Private Sub dtpAppointedDt_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dtpAppointedDt.KeyDown
        If e.KeyCode = Keys.Up Then
            dtpAppointedDt.Value = dtpAppointedDt.Value.AddDays(1)
        End If
        If e.KeyCode = Keys.Down Then
            dtpAppointedDt.Value = dtpAppointedDt.Value.AddDays(-1)
        End If
    End Sub

    Private Sub dtpReceivedDate_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dtpReceivedDate.KeyDown
        If e.KeyCode = Keys.PageUp Then
            dtpReceivedDate.Value = dtpReceivedDate.Value.AddDays(2)
        End If
        If e.KeyCode = Keys.PageDown Then
            dtpReceivedDate.Value = dtpReceivedDate.Value.AddDays(-2)
        End If
    End Sub

    Private Sub dtpDeadlineDate_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dtpDeadlineDate.KeyDown
        If e.KeyCode = Keys.PageUp Then
            dtpDeadlineDate.Value = dtpDeadlineDate.Value.AddDays(2)
        End If
        If e.KeyCode = Keys.PageDown Then
            dtpDeadlineDate.Value = dtpDeadlineDate.Value.AddDays(-2)
        End If
    End Sub

    Private Sub dtpcourtdate_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dtpCourtDate.KeyDown
        If e.KeyCode = Keys.Up Then
            dtpCourtDate.Value = dtpCourtDate.Value.AddDays(1)
        End If
        If e.KeyCode = Keys.Down Then
            dtpCourtDate.Value = dtpCourtDate.Value.AddDays(-1)
        End If
    End Sub

    Private Sub dtpsummonsdate_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dtpSummonsDate.KeyDown
        If e.KeyCode = Keys.Up Then
            dtpSummonsDate.Value = dtpSummonsDate.Value.AddDays(1)
        End If
        If e.KeyCode = Keys.Down Then
            dtpSummonsDate.Value = dtpSummonsDate.Value.AddDays(-1)
        End If
    End Sub

    Private Sub dtpcomplaintdate_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dtpComplaintDate.KeyDown
        If e.KeyCode = Keys.Up Then
            dtpComplaintDate.Value = dtpComplaintDate.Value.AddDays(1)
        End If
        If e.KeyCode = Keys.Down Then
            dtpComplaintDate.Value = dtpComplaintDate.Value.AddDays(-1)
        End If
    End Sub

    Private Sub dtpstatusdate_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dtpStatusDate.KeyDown
        If e.KeyCode = Keys.Up Then
            dtpStatusDate.Value = dtpStatusDate.Value.AddDays(1)
        End If
        If e.KeyCode = Keys.Down Then
            dtpStatusDate.Value = dtpStatusDate.Value.AddDays(-1)
        End If
    End Sub
0
Éric MoreauSenior .Net ConsultantCommented:
You should have been able to do only one method for all these:

   Private Sub dtpstatusdate_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dtpStatusDate.KeyDown, dtpComplaintDate.KeyDown,  dtpSummonsDate.KeyDown, dtpCourtDate.KeyDown, dtpDeadlineDate.KeyDown, dtpReceivedDate.KeyDown, dtpAppointedDt.KeyDown

dim x as datetimepicker = ctype(sender, datetimepicker)

        If e.KeyCode = Keys.Up Then
            x.Value = x.Value.AddDays(1)
        elseIf e.KeyCode = Keys.Down Then
            x.Value = x.Value.AddDays(-1)
        End If
    End Sub
0
moduloCommented:
Closed, 100 points refunded.

modulo
Community Support Moderator
Experts Exchange
0

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
Visual Basic.NET

From novice to tech pro — start learning today.

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.