Results 1 to 5 of 5

Thread: [RESOLVED] Changing focus

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    17

    Resolved [RESOLVED] Changing focus

    I'm working in VB5. I have an array of text boxes and want to change focus to the next in index order when the 'Enter' key is pressed.

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Candon City, Ilocos Sur, Phils.
    Posts
    11,044

    Re: Changing focus

    Something like this...

    VB Code:
    1. Private Sub txtData_KeyPress(Index As Integer, KeyAscii As Integer)
    2.     If KeyAscii = 13 Then
    3.         KeyAscii = 0
    4.         txtData(Index + 1).SetFocus
    5.     End If
    6. End Sub
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Re: Changing focus

    You should check if there is a next index, otherwise it will error on the last textbox.

    VB Code:
    1. Private Sub txtData_KeyPress(Index As Integer, KeyAscii As Integer)
    2.     If KeyAscii = 13 Then
    3.         KeyAscii = 0
    4.         If Index < txtData.UBound Then
    5.             txtData(Index + 1).SetFocus
    6.         End If
    7.     End If
    8. End Sub

    EDIT: You should make sure there are no holes in the index, otherwise you can get an error as well. eg if there is a txtData with index 0, 1, and 3, an error can be expected for the missing index 2
    Last edited by Frans C; Apr 28th, 2006 at 02:40 AM.
    Frans

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    17

    Re: Changing focus

    Thanks very much for the quick reply.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    17

    Re: Changing focus

    Thanks! You also answered my next question.

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