0

Here is the code that I have

MaskedTextBox timein1 = (MaskedTextBox)Time.Controls["txtTimeIn1"];
MaskedTextBox timein2 = (MaskedTextBox)Time.Controls["txtTimeIn2"];
MaskedTextBox timein3 = (MaskedTextBox)Time.Controls["txtTimeIn3"];
MaskedTextBox timein4 = (MaskedTextBox)Time.Controls["txtTimeIn4"];
MaskedTextBox timein5 = (MaskedTextBox)Time.Controls["txtTimeIn5"];
MaskedTextBox timein6 = (MaskedTextBox)Time.Controls["txtTimeIn6"];
MaskedTextBox timein7 = (MaskedTextBox)Time.Controls["txtTimeIn7"];

Is there anyway to create a For loop that will do all of this? I tried this, but it did not work.

for (int i = 1; i < 8; i++)
{
      string newField = "timein" + i;
      string txtField = "txtTimeIn" + i;

      MaskedTextBox newField = (MaskedTextBox)Time.Controls[txtField];
}

Thanks for the help.

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by sknake
0
for (int i1 = 1; i1 <= 7; i1++)
      {
        MaskedTextBox[] tbList = (MaskedTextBox[])this.Controls.Find("textBox" + i1.ToString(), true);
        if (tbList.Length == 1)
        {
          MaskedTextBox textBox = tbList[0];
          textBox.Text = i1.ToString();
        }
      }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.