Could somebody help me out with trying to clean up this big list of if / else if statements please? I've found that switch statements won't work because it won't handle a TextBox as the parameter. I've seen many answers involving the Dictionary, but those won't work either in my case.
private void SelectNextTextBox()
{
TextBox newTextBox = null;
if (_currentTextBox == keyText1)
{
newTextBox = keyText2;
}
else if (this._currentTextBox == keyText2)
{
newTextBox = keyText3;
}
else if (this._currentTextBox == keyText3)
{
newTextBox = keyText4;
}
else if (this._currentTextBox == keyText4)
{
newTextBox = keyText5;
}
else if (this._currentTextBox == this.keyText5)
{
newTextBox = regText1;
}
else if (this._currentTextBox == regText1)
{
newTextBox = regText2;
}
else if (this._currentTextBox == regText2)
{
newTextBox = regText3;
}
else if (this._currentTextBox == regText3)
{
newTextBox = regText4;
}
else if (this._currentTextBox == regText4)
{
newTextBox = regText5;
}
else
{
return;
}
newTextBox.SelectAll();
newTextBox.Focus();
}
There's 10 total text boxes and when one is full it changes to the next. This is the method that tells it which text box is next in the list.
this
in the given context? \$\endgroup\$WinForms
? Just set theTabOrder
of the controls. \$\endgroup\$