title: Removing a specific Row in TableLayoutPanel
body: <p>I have TableLayoutPanel that I programatically add Rows to. The User basically choses a Property and that is then displayed in the table along with some controls. I think I have a general understanding problem here and I will try to explain it.</p>
  
  <p>One of the Controls in every row is a 'delete'-Button. That button should delete the row it is in. What I did is add an eventhandler to the button and set the current rowcount.</p>
  
  <pre><code>deleteTalent.Click += (sender, e) =&gt; buttonClickHandler(numberOfRows);
  </code></pre>
  
  <p>Code of the handler:</p>
  
  <pre><code>private void buttonClickHandler(int rowCount)
  {
      int count = rowCount - 1;
      for (int i = count; i &lt; (count + 5); i++)
      {
          balanceTable.Controls.RemoveAt(count);
      }
      balanceTable.RowStyles.RemoveAt(count);
      balanceTable.RowCount--;
  
  }
  </code></pre>
  
  <p>I looked at it for hours and played around. But I can't find a working clean solution. I'm also pretty new to C#</p>
  
  <p>Here's the complete Function that creates a new row:</p>
  
  <pre><code>private void addBalanceItems(ToolStripMenuItem item)
  {
      int numberOfRows = balanceTable.RowCount;
      if (numberOfRows &gt; 1)
      {
          balanceTable.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.AutoSize));
  
      }
      balanceTable.Height = numberOfRows * 45;
      Steigerungsrechner rechner = new Steigerungsrechner();
      string tag = item.Tag.ToString();
  
      //change that asap :(
      if (tag == "A") { rechner.column = 1; }
      if (tag == "B") { rechner.column = 2; }
      if (tag == "C") { rechner.column = 3; }
      if (tag == "D") { rechner.column = 4; }
      if (tag == "E") { rechner.column = 5; }
      if (tag == "F") { rechner.column = 6; }
      if (tag == "G") { rechner.column = 7; }
      if (tag == "H") { rechner.column = 8; }
  
      Label talentName = new Label();
      talentName.Text = item.Text;
      talentName.Height = standardHeight;
      talentName.TextAlign = ContentAlignment.MiddleLeft;
      talentName.AutoSize = true;
      Label cost = new Label();
      cost.TextChanged += (sender, e) =&gt; costChangeHandler(cost);
      cost.Height = standardHeight;
      cost.TextAlign = ContentAlignment.MiddleLeft;
      TextBox startValue = new TextBox();
      startValue.TextChanged += (sender, e) =&gt; startValueChangeHandler(rechner, startValue, cost);
      startValue.Height = standardHeight;
      startValue.TextAlign = HorizontalAlignment.Center;
      TextBox endValue = new TextBox();
      endValue.TextChanged += (sender, e) =&gt; endValueChangeHandler(rechner, endValue, cost);
      endValue.Height = standardHeight;
      endValue.TextAlign = HorizontalAlignment.Center;
      Button deleteTalent = new Button();
      deleteTalent.Text = "x";
      deleteTalent.Click += (sender, e) =&gt; buttonClickHandler(numberOfRows);
      deleteTalent.Height = standardHeight;
  
      balanceTable.Controls.Add(talentName);
      balanceTable.Controls.Add(startValue);
      balanceTable.Controls.Add(endValue);
      balanceTable.Controls.Add(cost);
      balanceTable.Controls.Add(deleteTalent);
      balanceTable.Visible = true;
      balanceTable.RowCount++;
  }
  </code></pre>
  
  <p>Any help would be greatly appreciated! :)</p>