Hi,
I have a form in which there are 11 textboxes and two button controls(Just example) ,I want the tab key control to be in the textbox1 when the form loads ,and then If I press Tab Key from keyboard then it will be on second number textbox and so on,currently in my form if I lay the textboxes in a correct sequence then it works perfectly For e,g. Textbox1 and then textbox2 and so on ,but If the textbox numbers are not in the sequence then after pressing tab key the control will be on the second number textbox and it might be on the bottom and there are some textboxes with in those two textboxes.I want the control to be on the second number of textbox regardless of the textboxes numbers.
How can I accomplish that?

Dani AI

Generated

Good call by — using the designer Tab Order and explicitly setting which control has initial focus is the right approach. To expand: the running order is driven by each control’s TabIndex (lowest first) and whether the control is tabbable (TabStop = True, Visible = True, Enabled = True). That means visual placement or control names don’t matter — the numbers do.

Common causes when tabbing "jumps" unexpectedly

  • Some controls (or containers) have their own child TabIndex sequence, so controls inside a GroupBox/Panel are ordered relative to that container.
  • Non-interactive controls or ones you don’t want in the chain must have TabStop = False.
  • Multiline TextBoxes with AcceptsTab = True will consume Tab key presses.
  • Dynamically added controls inherit default TabIndex; set it when you add them.

Programmatic fixes you can apply

  • Set explicit TabIndex values in code (useful for runtime-created controls), then set the initial focus after the form finishes layout. Example:
    
    TextBox1.TabIndex = 0
    TextBox2.TabIndex = 1
    TextBox3.TabIndex = 2

Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
Me.ActiveControl = TextBox1
End Sub

' or, to set focus once the message loop is running:
Me.BeginInvoke(Sub() TextBox1.Select())



Quick checklist to resolve odd tab behavior
1) Use the designer Tab Order to confirm ordering, 2) check TabStop/Visible/Enabled on offending controls, 3) verify TabIndex inside any container controls, and 4) for runtime controls set TabIndex and set focus in Shown or via BeginInvoke. This covers the usual pitfalls when the visual layout doesn’t match the tab sequence.

Recommended Answers

All 2 Replies

In the Form Load handler you can set focus to the desired control like

TextBox1.Focus

When in design mode, under the View menu item, select Tab Order. This will show a number on each control. As you click on each control the tab order will be set to that sequence. That will be the order in which the controls will get focus as you use the tab key when running the program.

that is good :) thanks Reverend Jim thanks a lot :).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.