Results 1 to 5 of 5

Thread: moving cursor to next tabindex on enter key press

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    10

    moving cursor to next tabindex on enter key press

    Hi
    I have a form and I want to allow user to navigate all fields using "enter key" but I don't want to do it using arrays.I have to use this in many form so I need just one function which i will write inside form_keypress() event.It will read the current tabindex and shift cursor to next tabindex on enter ket press.


    Private Sub Form_KeyPress(KeyAscii As Integer)

    If KeyAscii = 13 Then

    MsgBox KeyAscii

    ' THE CODE

    End If

    End Sub


    Please reply ASAP.


    thanks,

    sincerely,
    summerisland

  2. #2
    Frenzied Member HanneSThEGreaT's Avatar
    Join Date
    Nov 2003
    Location
    Vereeniging, South Africa
    Posts
    1,492

    Re: moving cursor to next tabindex on enter key press

    Use SendKeys.

    VB Code:
    1. SendKeys "{ENTER}"
    VB.NET MVP 2008 - Present

  3. #3
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: moving cursor to next tabindex on enter key press

    Here is a simple single line code
    For this code to work, first set KeyPreview = True at design time.
    VB Code:
    1. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    2.     If KeyCode = vbKeyReturn Then SendKeys "{TAB}"
    3. End Sub
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  4. #4
    Lively Member mowafy's Avatar
    Join Date
    Jul 2005
    Posts
    116

    Re: moving cursor to next tabindex on enter key press

    Private Sub Form_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
    SendKeys ("{tab}")
    KeyAscii = 0
    End If
    End Sub

  5. #5
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: moving cursor to next tabindex on enter key press

    Here is an alternative solution. It's more complicated, but may be of interest.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_KeyPress(KeyAscii As Integer)
    4.   Dim c As Control
    5.   Dim f As Boolean
    6.   If KeyAscii = Asc(vbCr) Then
    7.     For Each c In Me.Controls
    8.       If c.TabIndex = ActiveControl.TabIndex + 1 Then
    9.         c.SetFocus
    10.         f = True
    11.         Exit For
    12.       End If
    13.     Next
    14.     'If we are at the end of the tab order then set focus to the first control.
    15.     If Not f Then Text1.SetFocus
    16.   End If
    17. End Sub
    This world is not my home. I'm just passing through.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width