Duplicate a row on a form
<p>I have a form which initially has one row of boxes for user input. I have a button which, when clicked, should create an identical row below the previous. The button should be able to be clicked more than once, to add multiple rows.</p>

<p>How can I go about implementing this, in a way which gives each control in each row its own unique name (so I can refer to it in my program), and also keeping proper formatting of the rows?</p>

<p>I have tried to set up a class for rows as below:</p>

<pre><code>class SubjectRow
{
  //every row has these boxes, plus some more textboxes
  public ComboBox subjectBox;
  public Label maxBox;
  public TextBox aBox;

  public SubjectRow(ComboBox _subjectBox, Label _maxBox, TextBox _aBox)
  {
    subjectBox = _subjectBox;
    maxBox = _maxBox;
    aBox = _aBox;
  }
}
</code></pre>

<p>...But I am stumped on how to have the button generate the new controls with their own names. My idea was something like this:</p>

<pre><code>buttonClicked
{
  SubjectRow row1 = new SubjectRow(subjectBox1, maxBox1, aBox1);
}
</code></pre>

<p>But I need a way to change the control names here without manually typing them all out; there could possibly be <em>a lot</em> of rows on the form.</p>

<p>Is there a way to add more rows to my form using a button, giving each control in each row a unique name? This needs to be done in some kind of loop.</p>