Auto Tab

Hi guys,
it's probably really easy, but I'm just starting out and need a bit of help.
How can i get my form to go automatically to the next textbox once the maximum charcters have been filled in
(If I'm posting in the wrong place tell me)
thanks,

chris
(it's hard being new :-( )


Answer this question

Auto Tab

  • BobSw

    just tried it but get: an error that:
    "length is not a member of System.Windows.Forms.Form"

    Private Sub TextBoxZichtrekening1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBoxZichtrekening1.TextChanged

    'TextBoxZichtrekening1.Length = 3

    If TextBoxZichtrekening1.Length = TextBoxZichtrekening1.MaxLength Then

    TextBoxZichtrekening2.Focus()

    End If

    End Sub

    am I doing something wrong

    thanks again,

    Chris


  • tml2004

    You can handle TextChanged event of the TextBox, and compare its Text.Length to MaxLength. If it is true, you can call SelectNextControl to move the focus.

    You need try a little bit to see whether it is the behavior you want.

    Since you could have many TextBoxes like this on your form.  You can create your own TextBox class, which inherits from the standard TextBox, so you won't dup that code.

    Lifeng

  • Ken Byrd

    HI Chris, you are really close on this one. Here is a sample that does what you want.


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

    TextBox1.MaxLength = 10

    If TextBox1.Text.Length = TextBox1.MaxLength Then

    TextBox2.Focus()

    End If

    End Sub

    The length property for the Textbox is for the Length of the TEXT in the textbox.
    that is where your problem is.
    The sample I included uses only two textboxes. If you have several on the form, the Tab Order could effect this code. ( I haven't tested it to see)
    james
    aka:Trucker


  • Joe2007

    Brilliant! Thanks.

    I'll probably be back in with more questions later on.

    thanks everyone for helping,

    Chris

  • hebert

    Thanks Lifeeng,

    but I'm really new - (and not very good - but I'm trying)
    this is what I've written so far:

    Private Sub TextBoxZichtrekening1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBoxZichtrekening1.TextChanged

    TextBoxZichtrekening1.MaxLength = 3

    If TextBoxZichtrekening1.MaxLength Then

    TextBoxZichtrekening2.Focus()

    End If

    End Sub

    but it goes to the next tab after one number is entered not three

    Sorry, if I'm being dumb

    can you help

    Thanks again.
     
    chris


  • kunal.kb

    Change your "if textboxzl...MaxLength Then" to "if TextBox...Length = TextBox..MaxLength Then".
  • Auto Tab