?
Solved

Date Time Picker + Add Days

Posted on 2004-11-18
8
Medium Priority
?
389 Views
Last Modified: 2012-06-27
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?
0
Comment
Question by:computerg33k
7 Comments
 
LVL 18

Expert Comment

by:armoghan
ID: 12622070
Not fully understood, This example may help
http://www.codeproject.com/cs/miscctrl/cstimepicker.asp
0
 
LVL 2

Expert Comment

by:ahmadfuwad
ID: 12622773
'try following code it will work fine

   Dim objdate As DateTime
        objdate = Me.DateTimePicker1.Text
        Me.TextBox1.Text = objdate.AddDays(7)
0
 
LVL 4

Author Comment

by:computerg33k
ID: 12627137
"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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Expert Comment

by:armoghan
ID: 12641263
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
 
LVL 4

Author Comment

by:computerg33k
ID: 12668829
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
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 12668958
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
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12691089
Closed, 100 points refunded.

modulo
Community Support Moderator
Experts Exchange
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Screencast - Getting to Know the Pipeline
Suggested Courses

862 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