MaxLength of textbox and Focus change

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.
 
S

Sender

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
 
G

Guest

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...
 
H

Herfried K. Wagner [MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top