VB.NET - How to get focus on Motth and Year In datetime picker using Enter

Asked By azhar rahi on 02-Mar-07 02:44 AM

Hi Hope all be fine and happy here

I want a solution for getting focus first on Month , then on Year in DateTimePicker Control using Enter .. My date format is MM\yyyy and day is not included . When the control get focus then the month automatically get focused. I want when i press enter it must focus to year and also when i press enter second time the next control must be focused. Kindly tell me the solution as soon as possible.

     Thanks

Capture onKeyPress

Robert Stanton replied to azhar rahi on 02-Mar-07 07:01 AM

You can capture the controls onKeyPress event adn try using send keys to change the neter key into the right key

Private Sub dateTimepicker1_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) _
        Handles dateTimepicker1.KeyPress

 If e.KeyChar == 13 Then
   SendKeys.Send("{right}");
            e.Handled = True
 End If

End Sub

Give this a try, let us know how it works

How to focus over Year after using KeyPress event

azhar rahi replied to Robert Stanton on 02-Mar-07 08:38 AM

I know about this event which you described. The problem is that i want to check if the focus is on Month then on enter key press it must transfer to year and if the focus is on year then on key press it must focus on next control.

  the major problem is to transfer focus from month to year .. How can i do it . there is no select or focus function available with month and year properties of DateTimePicker.


in keydown event

sundar k replied to azhar rahi on 04-Mar-07 05:38 AM

in vb you can do this by placing the below code in DTPicker Keydown event, similarly i think you can do it in vb.net, where 13 is the keycode for "enter key"  

If KeyCode = 13 Then KeyCode = vbKeyRight

assuming the initial focus is on month value