Link to home
Start Free TrialLog in
Avatar of Com1uk
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
Prasad
Avatar of Anastasia D. Gavanas
Anastasia D. Gavanas
Flag of Greece image

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
ASKER CERTIFIED SOLUTION
Avatar of appari
appari
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Com1uk
Com1uk

ASKER

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 ?

Thanks
Prasad
Avatar of Com1uk

ASKER

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
Prasad
any progress?
Avatar of Com1uk

ASKER

Hi Appari,

Thanks for giving solution. It's working fine.

Regards
Prasad