Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
I have multiple TextBox on one Form in my application, and I have to change focus one by one just like pressing Tab when they are filled.
Posted
Updated 27-May-11 7:53am
v2
Comments
Sergey Alexandrovich Kryukov 27-May-11 12:39pm    
Tag it! WPF, Forms, APS.NET, what?!
--SA

See Focus[^] method.
 
Share this answer
 
Comments
RaviRanjanKr 28-May-11 0:58am    
Good Suggestion, My 5 :)
Handle TextBox.ModifiedChanged[^] events.

When user has enter enough text, you can set focus to the next TextBox.


C#
private void TextBox1_TextChanged(object sender, EventArgs e)
{
  this.textBox1.Modified = false; // Get next event.

  // Check text input
  if (this.textBox1.Text.ToUpper() == "AGREE")
  {
    Control nextInTabOrder = GetNextControl(this, true);
    nextInTabOrder.Focus();
  }
}
 
Share this answer
 
Comments
fcronin 27-May-11 18:02pm    
Is good (sorry, meant to hit 5), but I would recommned OP create a custom control that can handle multiple triggers for when the content of a given textbox is 'complete'. By number of characters, by content match, by format, etc... The custom control should raise a custom event to notify the parent, and this is the event that should be handled there to advance focus. That way, the control takes care of monitoring it's own content and deciding when it is 'done', then just tells the parent when that happens.
Kim Togo 28-May-11 5:15am    
Thanks fcronin
You are right about a custom control of TextBox class. It will be a more elegant solution.
How about add your own solution with a custom control ? :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900