5 Replies - 3381 Views - Last Post: 25 March 2013 - 05:40 AM Rate Topic: -----

#1 Adqusit  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 152
  • Joined: 02-March 13

How to control TabIndex with Enter Key and not with Tab Key

Posted 19 March 2013 - 06:00 AM

Hi. All my form controls are set to tabIndex from 0 to 9 lets say, right; Meaning thereby that as i press the tab key so the focus transfer to the next control on the form and then so on, right. I want to control this transferring by using Enter button not by Tab Key? Lets suppose after inserting the value in first textbox i press the enter button and the control transfer to the next control and then so on? I hope my idea would be clear? Is is possible?

This is my code.
 If e.KeyChar = Microsoft.VisualBasic.Chr(13) Then
  SendKeys.Send(vbTab)         End If


Please guide me for this and

Secondly, guide me for that whether using the Enter Key instead of Tab key is a better option or not?

Is This A Good Question/Topic? 0
  • +

Replies To: How to control TabIndex with Enter Key and not with Tab Key

#2 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,505
  • Joined: 16-March 11

Re: How to control TabIndex with Enter Key and not with Tab Key

Posted 19 March 2013 - 06:50 AM

It's certainly possible. Now whether or not it's a better option is really a matter of your preference. On your form you'll want to set the KeyPreview Property to True, and then use the keydown event.

    Private Sub Form1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.KeyCode = Keys.Tab Then
            e.SuppressKeyPress = True
        ElseIf e.KeyCode = Keys.Enter Then
            SendKeys.Send(vbTab)
        End If
    End Sub


Was This Post Helpful? 0
  • +
  • -

#3 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: How to control TabIndex with Enter Key and not with Tab Key

Posted 20 March 2013 - 02:38 PM

View PostAdqusit, on 19 March 2013 - 07:00 AM, said:

Secondly, guide me for that whether using the Enter Key instead of Tab key is a better option or not?

As trevster344 Says, it's a matter of preference. Some people like it and some don't. The one problem (in my opinion) with using the method he showed you is that the user may ONLY use the Enter key. But, if you don't suppress the Tab key, adding the ability to use Enter doesn't take anything away from the program's friendliness, and adds cconsiderably to it for those that like to use Enter.

This post has been edited by lar3ry: 20 March 2013 - 02:44 PM

Was This Post Helpful? 0
  • +
  • -

#4 IronRazer  Icon User is offline

  • D.I.C Addict

Reputation: 236
  • View blog
  • Posts: 778
  • Joined: 01-February 13

Re: How to control TabIndex with Enter Key and not with Tab Key

Posted 20 March 2013 - 03:33 PM

Hey Adqusit,
Just to add to what the others have said, If you have any buttons on your form that you want to skip over when using the Enter key you will need to set the buttons (TabStop) property to False. If it sets focus to a button when you are tabbing threw the controls and you hit Enter it actually clicks the button. :bigsmile:
Was This Post Helpful? 0
  • +
  • -

#5 Adqusit  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 152
  • Joined: 02-March 13

Re: How to control TabIndex with Enter Key and not with Tab Key

Posted 25 March 2013 - 05:32 AM

Well, I think that i will be sticky with Tab Key.

This post has been edited by Adqusit: 25 March 2013 - 05:37 AM

Was This Post Helpful? 0
  • +
  • -

#6 Adqusit  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 152
  • Joined: 02-March 13

Re: How to control TabIndex with Enter Key and not with Tab Key

Posted 25 March 2013 - 05:40 AM

I've another issue with Enter Key on my combobox, which is set to AutoComplete. if i write the product, which is already available in combobox, so it gives error on its leave event (I'm using sor for Tab Key). The problem is that if press the Enter Key instead of tab key, so it does not give the error and the value which is recently written is removed?

Did you get my idea?

I've not applied any enter Key coding on my form, but its giving me thing problem. Please any guidance for this.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1