How to move focus on date part of DateTimePicker ?

Com1uk used Ask the Experts™
Hi All,

We are working on the windows application. Just for example we have following 3 fields and controls on the form

1) User Name - TextBox

2) Start Date - DateTimePicker

3) End Date - DateTimePicker

We have added tabbing on it and its working.

Tabbing sequence is in the following order

User Name
Start Date
End Date

In the DateTimePicker we are showing date in following format

29 May 2012

When we press tab key first we get focus on "User Name" and then on "Start Date" DateTimePicker i.e. on the date part of "Start Date" now again we press tab key and focus moves to date part of "End Date" DateTimePicker. This is the tabbing cycle.

Now again we continue to press tab key and get focus on "Start Date" DateTimePicker. At this stage if we press right arrow key then month part of "Start Date" DateTimePicker get selected. If we again press tab key then focus moves to date part of "End Date" DateTimePicker.

If we continue to press tab key then focus gets on month part of "Start Date" DateTimePicker instead of date part of it. We want that user should always get the focus on date part of DateTimePicker.

Please help us if anyone knows the solution for this.

Thanks and Regards
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2011

Top Expert 2011

or maybe this

dateTimePicker1.GotFocus += new EventHandler(dateTimePicker1_GotFocus);

void dateTimePicker1_GotFocus(object sender, EventArgs e)
    SendKeys.Send("{RIGHT 1}");
And on form load set focus to datetimepicker.

If your date field is tothe left, write the code as SendKeys.Send("{RIGHT 0}"); to set the focus on the date field
create your own custom control inherited from datetimepicker and use it.

add a new class and name it CustomDateTimePicker, add the following code to it.

Public Class CustomDateTimePicker
    Inherits DateTimePicker

    Private mRecreating As Boolean

    Protected Overrides Sub OnEnter(ByVal e As System.EventArgs)
        If mRecreating Then Return
        mRecreating = True
        mRecreating = False
    End Sub
End Class

Open in new window

now add your custom control CustomDateTimePicker to the form and run the application.
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.


Hi ,

We tried this  SendKeys.Send("{RIGHT 0}");   but its not showing any effect.
Can you please try this at your end to reproduce the problem ?



Hi Appari,

Thanks for giving this code. We added it and it seems to be working fine.
We will test this more just to confirm it's not affecting any other part of code and let you know.

Thanks and Regards

any progress?


Hi Appari,

Thanks for giving solution. It's working fine.


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial