MaxLength of textbox and Focus change

  • Thread starter Thread starter GBW
  • Start date Start date
G

GBW

I'm new to VB .NET development - I'm trying to create a
text box that as soon 3 characters are entered the focust
will then move to the next text box I've tried using
MaxLength or textbox.selection.length = 3. It will move
the focus when you select the 4th character to enter but
I would like it to automatically move focus when 3
characters are entered. I know this must be simple but
I'm in the weeds right now... Thanks.
 
Instead of checking for 3 check for 2.

I checked with two textboxes textbox1, textbox2. Textbox1 has tabindex 1 and
textbox2 has tabindex 2.

I entered the following code. It works.

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TextBox1.TextChanged

If Len(TextBox1.Text) > 2 Then

TextBox2.Focus()

End If

End Sub
 
thank you! That definitely does work..I'm trying to
include this though with a keypress event. If someone
presses the "." button, I'd also like it to change focus.
(like ip address entry..) Can you include a keypress
event with a text changed event? Thanks again for
helping a newbie...
 
Hello,

thank you! That definitely does work..I'm trying to
include this though with a keypress event. If someone
presses the "." button, I'd also like it to change focus.
(like ip address entry..) Can you include a keypress
event with a text changed event? Thanks again for

You can use 'InStr' or the text's 'IndexOf' method to check if it contains a
"." character.
 
Back
Top