Avatar of Com1uk
 asked on

How to move focus on date part of DateTimePicker ?

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

Avatar of undefined
Last Comment

8/22/2022 - Mon
Anastasia D. Gavanas

Anastasia D. Gavanas

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

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

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 ?

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.

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.

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.