• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 481
  • Last Modified:

moving through components with TAB

Hi,
I'm working with VB6,
I have a form with text boxes, buttons and radio buttons,
I want the user to be able to move from one component to another by clicking the Tab or Enter,
right now, when clicking Tab it moves, but not in the order I want.
How can I change the order the Tab key moves on the components?

thanx
0
zolpo
Asked:
zolpo
  • 5
  • 3
  • 2
  • +2
3 Solutions
 
SRigneyCommented:
Each control has a TabOrder property.   0 is the lowest.

Go through each control and set the correct tab order.
A quick way to do it is to go through all controls starting with the last one in reverse order, and set the tab order for each to 0.

When you set the second to last one to 0 the last one gets changed to 1 by VB.

The problem is that when you put the controls onto your form, the tab order gets set to the order that the controls were added to the form.
0
 
ajexpertCommented:
Hi,
  You need to set the TabIndex property of each control.  TabIndexes should be start from where you want to get focus and increase it by 1.
0
 
zolpoAuthor Commented:
Hi,
I did what u suggested, but now, after I move with the TAB key,
the mouse is disabled, and I cant move through the components with the mouse, but only with the Tab key
Thanx
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ajexpertCommented:
This doesn't disables the mouse anyway.  Can you tell us what you did exactly
0
 
zolpoAuthor Commented:
Hi.
I changed the TabIndex like u said,
I clicked with the mouse on each component and changed the tabIndex to the number i wanted, I didnt change all of the components' tabindex, only those I needed to change
thanx
0
 
Arthur_WoodCommented:
when you change the Tabs of selected controls, you MUST do this in the REVERSE order of how you want to navigate through the controls.

Every control placed on a page gets a DEFAULT tabIndex value, which is the ORDER in which they were ORIGINALLY placed on the page.  So the First control placed on the form gets 0, the next one gets 1 and so on. And it is NOT possible for two controls to have the same TabIndex.

When you change the TabIndex of any control, all of the controls that have indexes the same OR higher that the one you are re-indexing, have their tabIndexes changed (increased by 1) to make room for the control that you are assigning the new TabIndex for.  Thus, you make sure that the controls get the TabIndex that you want them to have, Start with the Control that you want to be LAST, and set its TabIndex to 0, then go to the control that you want to be NEXT_TO_LAST, and again set ITS tabindex to 0 (yes, I said set that one to 0 - the one that you previous set to 0 will be changed to TabIndex 1) continue this process until you get to the Control that you want to be FIRST, and again set its TabIndex to 0.  Now the TabIndexes will be 0...N in the CORRECT ORDER!!!!.

AW
0
 
zolpoAuthor Commented:
Hi,
Thanx, it works now,
as to my other q, how can I use Enter key to do the same as Tab?
0
 
vinnyd79Commented:
You could set the focus to the next control in the KeyPress Event:

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
    Text2.SetFocus
End If
End Sub
0
 
vinnyd79Commented:
or use sendkeys to send a tab

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then SendKeys "{Tab}"
End Sub
0
 
SRigneyCommented:
Another method to prevent code changes if you change the tab order again is to use

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
    SendKeys "{TAB}"
End If
End Sub

0
 
zolpoAuthor Commented:
Hi,
Thank guys!!!!
one more thing, when the form loads, I want the cursor to be in a text box
indexed 0,
right now, I need to click the mouse inside the textbox to see the cursor
THANX A LOT!!!!
0
 
SRigneyCommented:
Try
If TextBox1.Visible Then TextBox1.SetFocus

I find it best to put this in the Form1_Activate event

The only possible problem is if the form isn't the only form, then I use a little work around to keep the focus from going back to the first field everytime that form become the focus.

I'm winging it with this code the declaration will be a little different.
Sub Form1_Activate
Static FirstTime as Bool = True
   If FirstTime Then
      If TextBox1.Visible Then
         TextBox1.SetFocus
      End If
      FirstTime = False
   End If
End Sub
0
 
zolpoAuthor Commented:
Hi,
Thanx guys, u all helped me a lot!!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 5
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now