How do i programatically tab to the next field?

  • Thread starter Thread starter Dan Keeley
  • Start date Start date
D

Dan Keeley

Hi,

I want to make the enter key in certain fields do the same as the tab key

I've caught the KeyPress event for the enter key, however I cannot find the
function to call in order to tab to the next field??

I just want to do a generic event handler, so if i need to specify a tab
number can i get the tab index of the current field from:

Private Sub EnterHandler(ByVal sender As System.Object, ByVal e As
KeyPressEventArgs)

sender?


Thanks!
Dan
 
You can use the GetNextControl Method of the control you want to move from.
After capturing the Enter key then get the next control and then set the
focus to that control.


Lloyd Sheen
 
* "Dan Keeley said:
I want to make the enter key in certain fields do the same as the tab key

I've caught the KeyPress event for the enter key, however I cannot find the
function to call in order to tab to the next field??

\\\
Me.GetNextControl(Me.ActiveControl, False).Focus()
///
 
\\\
Me.GetNextControl(Me.ActiveControl, False).Focus()
///

Hmm, that sounds perfect, except that it doesnt work. Focus appears to go
nowhere... Nothing clearly has focus and if i then tab it seems to return
to the field i was just trying to get out of!?

I've double checked the component i'm on, and tab index is indeed
consecutive... Is that not the numeric ordering it uses?

How can i find out where focus is?

Rgds,
Dam
 
Herfried K. Wagner said:
'Me.ActiveControl' will return a reference to the active control.

Excellent that helped me fix the problem.

Thanks loads!!!
Dan
 
Yos Yul,
Have you tried SelectNextControl?

Something like:
If e.KeyChar = ControlChars.Cr Then
e.Handled = True
Me.SelectNextControl(TextBox1, True, True, True, True)

Be certain to read the help on the four parameters that I made True.

Hope this helps
Jay
 
Back
Top