Force a Tab
-
I have tried to search for an answer on line but maybe my search choices are worded wrong. I have a form that has multiple text boxes. (Just like many forms) I am using a barcode scanner to input data into the textboxes. I put a enter post amble in the scanner to go to the next field, and it works. The form gives the user the ability to lock fields and keep those values in the textboxes for multiple iterations of the form entry. I lock textfields by changing enabled to false. Issue: When I scan the text box previous to a locked textbox the cursor will not tab over the locked field. I do not want to put a tab in the scanner do to other issues on that page. I want to know if there is a way to force a tab through code. Example: When the textbox is validated then force tab to tab to next unlocked textbox. Thank you for any help you offer.
-
I have tried to search for an answer on line but maybe my search choices are worded wrong. I have a form that has multiple text boxes. (Just like many forms) I am using a barcode scanner to input data into the textboxes. I put a enter post amble in the scanner to go to the next field, and it works. The form gives the user the ability to lock fields and keep those values in the textboxes for multiple iterations of the form entry. I lock textfields by changing enabled to false. Issue: When I scan the text box previous to a locked textbox the cursor will not tab over the locked field. I do not want to put a tab in the scanner do to other issues on that page. I want to know if there is a way to force a tab through code. Example: When the textbox is validated then force tab to tab to next unlocked textbox. Thank you for any help you offer.
Check that your locked control has TabStop property set to false. That could be the reason if the focus goes to the locked control. Also since you now the layout of your form, one way could be that you programmatically use SetFocus method on the control where you want to go.
The need to optimize rises from a bad design.My articles[^]
-
I have tried to search for an answer on line but maybe my search choices are worded wrong. I have a form that has multiple text boxes. (Just like many forms) I am using a barcode scanner to input data into the textboxes. I put a enter post amble in the scanner to go to the next field, and it works. The form gives the user the ability to lock fields and keep those values in the textboxes for multiple iterations of the form entry. I lock textfields by changing enabled to false. Issue: When I scan the text box previous to a locked textbox the cursor will not tab over the locked field. I do not want to put a tab in the scanner do to other issues on that page. I want to know if there is a way to force a tab through code. Example: When the textbox is validated then force tab to tab to next unlocked textbox. Thank you for any help you offer.
It sounds like there is no set tab order, that you are figuring out at runtime. I use this to enable/disable our controls tabstops,
''' ''' This sets the tab stops to false when in inquire mode and tab stops to true if in update mode. ''' ''' C is the control from the calling form ''' This sets the control tabstops to True (enabled) false (disabled) ''' Public Sub sInitializeControls(ByVal c As Control, ByVal bStatus As Boolean) 'This routine needs to be ran after a form is loaded 'When we enable and disable controls the cursor will stop on the controls that have been disabled 'This is a recursive function 'c = Control from Calling form ' Dim ctrl As Control For Each ctrl In c.Controls If String.Compare(ctrl.Name, "btnClose") = 0 Or String.Compare(ctrl.Name, "btnCancel") = 0 Then 'exit Else ctrl.TabStop = bStatus If ctrl.HasChildren Then sInitializeControls(ctrl, bStatus) End If End If Next End Sub
You might be able to modify this to your needs. I would think you could call this to set all tab stops false and then in the validation routine you could set the specific control you are wanting to move to like so control.tabstop = true control.focus() or control.select()I have found the latter of these two to be more reliable
Humble Programmer
-
It sounds like there is no set tab order, that you are figuring out at runtime. I use this to enable/disable our controls tabstops,
''' ''' This sets the tab stops to false when in inquire mode and tab stops to true if in update mode. ''' ''' C is the control from the calling form ''' This sets the control tabstops to True (enabled) false (disabled) ''' Public Sub sInitializeControls(ByVal c As Control, ByVal bStatus As Boolean) 'This routine needs to be ran after a form is loaded 'When we enable and disable controls the cursor will stop on the controls that have been disabled 'This is a recursive function 'c = Control from Calling form ' Dim ctrl As Control For Each ctrl In c.Controls If String.Compare(ctrl.Name, "btnClose") = 0 Or String.Compare(ctrl.Name, "btnCancel") = 0 Then 'exit Else ctrl.TabStop = bStatus If ctrl.HasChildren Then sInitializeControls(ctrl, bStatus) End If End If Next End Sub
You might be able to modify this to your needs. I would think you could call this to set all tab stops false and then in the validation routine you could set the specific control you are wanting to move to like so control.tabstop = true control.focus() or control.select()I have found the latter of these two to be more reliable
Humble Programmer
I have tried changing the tab stop with no luck. So, are you saying there is no way to force a tab through code?
-
Check that your locked control has TabStop property set to false. That could be the reason if the focus goes to the locked control. Also since you now the layout of your form, one way could be that you programmatically use SetFocus method on the control where you want to go.
The need to optimize rises from a bad design.My articles[^]
I have tried the tabstop idea. It still does not work. I Need to know if there is a way to force a tab in code. If I can I think it will work. I want to try that before I write a bunch of code to change focus.
-
I have tried changing the tab stop with no luck. So, are you saying there is no way to force a tab through code?
does the gotfocus/enter routine fire if you hit tab? if so, test if the control is disabled and then issue a
My.Computer.Keyboard.SendKeys("{TAB}")
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous 'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
-
I have tried the tabstop idea. It still does not work. I Need to know if there is a way to force a tab in code. If I can I think it will work. I want to try that before I write a bunch of code to change focus.
You can simulate tab with SendKeys, but I think it would be easier to call for example: Select Method[^]. When you say that it doesn't work, do you mean that the focus goes to the locked control even though it's TabStop is False or does tho focus go somewhere else?
The need to optimize rises from a bad design.My articles[^]
-
I have tried to search for an answer on line but maybe my search choices are worded wrong. I have a form that has multiple text boxes. (Just like many forms) I am using a barcode scanner to input data into the textboxes. I put a enter post amble in the scanner to go to the next field, and it works. The form gives the user the ability to lock fields and keep those values in the textboxes for multiple iterations of the form entry. I lock textfields by changing enabled to false. Issue: When I scan the text box previous to a locked textbox the cursor will not tab over the locked field. I do not want to put a tab in the scanner do to other issues on that page. I want to know if there is a way to force a tab through code. Example: When the textbox is validated then force tab to tab to next unlocked textbox. Thank you for any help you offer.
-
I have tried to search for an answer on line but maybe my search choices are worded wrong. I have a form that has multiple text boxes. (Just like many forms) I am using a barcode scanner to input data into the textboxes. I put a enter post amble in the scanner to go to the next field, and it works. The form gives the user the ability to lock fields and keep those values in the textboxes for multiple iterations of the form entry. I lock textfields by changing enabled to false. Issue: When I scan the text box previous to a locked textbox the cursor will not tab over the locked field. I do not want to put a tab in the scanner do to other issues on that page. I want to know if there is a way to force a tab through code. Example: When the textbox is validated then force tab to tab to next unlocked textbox. Thank you for any help you offer.
This shouldn't even be an issue. How I did it in the past is enable the Form's KeyPreview, then handle it's KeyDown event. This handler should look for the preamble keysequence, eat the keys so they don't go to the controls, then start reading each key and appending to a string, until you see the postamble sequence, being sure to eat those keys. Then you've got the barcode, having never input the thing into a TextBox.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008