title: C# - loading text boxes with a foreach loop
body: <p>I'm back looking for a solution on how to load my array into certain text boxes. I posted a similar question the other day. The answer that was provided was good however now I'm having what I believe to be a problem with positioning within the code. This is what I have:</p>
  
  <pre><code>    private void btnQuickPlayNumbers_Click(object sender, EventArgs e)
      {
          int randCheck = 0;
  
          Random rand = new Random();
  
          int[] powerball5 = new int[5];
  
          for (int i = 0; i &lt; powerball5.Length; )
          {
              randCheck = rand.Next(0, 60);
  
              while (!(powerball5.Contains(randCheck)))
              {
                  powerball5[i] = randCheck;
  
                  foreach (Control x in this.Controls)
                  {
                      if (x is TextBox)
                      {
                          ((TextBox)x).Text = powerball5[i].ToString();                            
                      }
                  }
  
                  i++;
              }                
          }
      }
  </code></pre>
  
  <p>Now this loads all the text boxes on my forum and that is fine however it is loading the same number in all of them. This is a powerball program and I need to load my array into the boxes as so:</p>
  
  <p>textbox1 = powerball5[0];
  textbox2 = powerball5[1];
  ect., ect.</p>
  
  <p>I have a total of 5 boxes that I'm trying to load. We came to the conclusion that the reason this loads the same number into all of them is that the position of the foreach loop doesn't allow for the array to be loaded and the counter to increment. I have tried moving it around and even making its own method, but when I do it as it's own method I get an index out of range error. So I'm a little lost on what to do. Any help would be greatly appriciated. If you need any more info I will try to update this the best I can to meet the needs of everyone. Thank you again for your time.</p>