We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

How to enable tabbing from hours to minutes in the datetimepicker?

Medium Priority
312 Views
Last Modified: 2013-11-26
I am a using quite a few datetimepickers set to a CustomFormat of military time:
         dtpTimeToYard.CustomFormat = Format("HH:mm")
The problem is that my users want to tab from the hours to the minutes portion and are very annoyed that they can't do this.  How do I give them this capablity?  I have told them that they can use the right arrow key but this does not appease them.  Thanks for your help!  
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
The Tab key is a dialog key, and requires special programming:

Convert Enter and Escape keys to Tab and Shift-Tab for easy navigation in Visual Basic .NET
http://www.vb-helper.com/howto_net_enter_esc_to_tab.html
Example:
 
' Convert Enter and Escape keys
' into Tab and Shift-Tab.
' Thanks to Luis XV (luisxvarg@hotmail.com).
Protected Overloads Overrides Function _
    ProcessDialogKey(ByVal keyData As Keys) As Boolean
    Select Case keyData
        Case Keys.Enter
            Return MyBase.ProcessDialogKey(Keys.Tab)
        Case Keys.Escape
            Return MyBase.ProcessDialogKey(Keys.Shift Or _
                Keys.Tab)
    End Select
    Return MyBase.ProcessDialogKey(keyData)
End Function

Open in new window

Commented:
Thanks so much for replying to my neglected question.  I tried your suggestion, but I need the tab key to act like an right arrow key and jump from the hours to the minutes field in the datetimepicker.  In all other controls I need the tab key to act like the tab key.  In the end, I just settled on capturing the key_down event for the Enter key (which is on the number pad).      
Thanks again for your help!

  Private Sub dtpTimeToYard_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dtpTimeToYard.KeyDown
               If e.KeyCode = Keys.Enter Then
            SendKeys.Send("{RIGHT}")
        End If
    End Sub

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
On the other hand, I think my users will be thrilled if they can use the enter key that's on the number pad instead of the tab key.  But then, how should they navigate to from hours to minutes?  I don't want to use a non-intuitive character on the number pad.  Thanks for your help!
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
That post was only to show you the realm of possibilities, and not to be a specific answer to your question.  

Do you still need advice?

Author

Commented:
If you know of a way to use the Enter key instead of the Tab key and still have the Enter key jump from hours to minutes in the datetimepicker, that would be great.  Otherwise, I think I'm good.  Thanks so much for your help!  
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
Are you saying that this didn't work?


 Private Sub dtpTimeToYard_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dtpTimeToYard.KeyDown
               If e.KeyCode = Keys.Enter Then
            SendKeys.Send("{RIGHT}")
        End If
    End Sub

Open in new window

Author

Commented:
It works, but not when I override the Enter key to act as a Tab key.  
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
I don't quite understand the problem.  Are you saying that you want the <Enter> key to tab to the next part of the control, or to another control?

Author

Commented:
Can it do both?
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
How would you like to do that exactly?

      hh<enter>mm<enter>ss<enter>  --> next control

Author

Commented:
Yes!
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008
Commented:
The problem with that kind of functionality is that you have no idea where you are in the control.  There would be no way to distinguish that you are on the last part, and you need to tab, instead of right arrow.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.