Text box to go to next tab index control

G

Guest

When the max length of a text box has been reached, I want the focus to go to
the next control based on tab index. How do I code or what property do I set?
 
T

Tim Wilson

You could do something similar to the following.

private void textBox1_TextChanged(object sender, System.EventArgs e)
{
if (this.textBox1.TextLength == this.textBox1.MaxLength)
{
this.SelectNextControl(this.textBox1, true, true, true, true);
}
}

--
Tim Wilson
..NET Compact Framework MVP

Mike L said:
When the max length of a text box has been reached, I want the focus to go to
the next control based on tab index. How do I code or what property do I
set?
 
J

jeremiah johnson

Tim said:
You could do something similar to the following.

private void textBox1_TextChanged(object sender, System.EventArgs e)
{
if (this.textBox1.TextLength == this.textBox1.MaxLength)
{
this.SelectNextControl(this.textBox1, true, true, true, true);
}
}

I'd do it on KeyUp, because I believe TextChanged doesn't fire until the
control loses focus (i might be thinking of javascript though).

private void textBox1_KeyUp(object sender, KeyEventArgs e) {
if (textBox1.TextLength == textBox1.MaxLength) {
textBox2.Focus();
}
}

actually I just tried it and textchanged does work after every keypress.
So either TextChanged or KeyUp will work for you.
 

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