?
Solved

Using DateTimePicker with a checkbox and up down control

Posted on 2011-04-26
7
Medium Priority
?
268 Views
Last Modified: 2012-05-11
I am using VB2010 and winforms.

I am working with a DateTimePicker control where the ShowCheckBox is true and ShowUpDown is true.  The format of the control is Short Date.  

I am having a problem when the control is originally unchecked, and then the user checks it to enable it and tries to use the up and down arrows, but nothing happens.  I am guessing this is because none of the fields (month, day or year) are selected, so it doesnt know what is supposed to be increased/decreased.  I cant see any events that i can use to either select the day field, or capture the up down events to manually increase/decrease the date.  In addition, when the user increases the day past the end of the month, i would like it to go to the next month/year (ie they increase date from 1/30/10 to 1/31/10 and then 2/1/10 instead of it going back to 1/1/10).  Really i need to capture the click on the up and down buttons to do this...

any suggestions?  If i cant do this, i will need to use 3 seperate controls (checkbox, textbox and a up down control) and lots of code.

Jeff
0
Comment
Question by:BritishJeffrey
  • 5
  • 2
7 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35472105
Try the ValueChanged event:
Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
    If Me.DateTimePicker1.Enabled Then
      SendKeys.Send("{RIGHT}")
    End If
End Sub

Open in new window

0
 

Author Comment

by:BritishJeffrey
ID: 35475317
Thanks for the suggestion kaufmed, but for some reason the builtin checkbox does not change the value of enabled, even though it effectively does change the enabled prroperty!  This means that whenever the valuechanged property is raised (either through the checkbox or when you change a value in the datetimepicker), the routine will be called and sendkeys will be sent.

Jeff
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35476130
But is that really a big deal? If you send a "Right" to the DateTimePicker, but the text isn't "selectable", what has broken?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35476347
Heheh....  never mind. I see why that's a bad idea now. Let's switch things up a bit, shall we?
Public Class Form1
    Private sendKey As Boolean
    Private firstSend As Boolean

    Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
        If Me.DateTimePicker1.Checked Then
            If Not sendKey AndAlso firstSend Then
                SendKeys.Send("{RIGHT}")
                firstSend = False
            End If
        Else
            firstSend = True
            sendKey = False
        End If
    End Sub
End Class

Open in new window

0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 35476388
Disregard the previous post...  I promise I wasn't drinking when I created it, but I can't telly what I was thinking  = )

This should be more to the point:
Public Class Form1
    Private sendKey As Boolean

    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()

        sendKey = Not Me.DateTimePicker1.Checked
    End Sub

    Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
        If Me.DateTimePicker1.Checked Then
            If sendKey Then
                SendKeys.Send("{RIGHT}")
                sendKey = False
            End If
        Else
            sendKey = True
        End If
    End Sub
End Class

Open in new window

0
 

Author Comment

by:BritishJeffrey
ID: 35476437
Wow, this works.  I thought i had tried every combination of booleans to get this to work, but i must have missed this combination.  Thanks so much.  
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35477088
NP. Glad to help  : )
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Loops Section Overview
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month16 days, 5 hours left to enroll

850 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