I have a TableLayputPanel with 2 columns and 4 rows and I'm trying to add buttons to it at runtime. I want to dynamically add each button to the first cell:
private int nextIndex = 1;
private void bAddButton_Click(object sender, EventArgs e)
{
Button newButton = new Button();
newButton.Text = nextIndex.ToString();
tableLayoutPanel1.Controls.Add(newButton, 0, 0); // first cell
nextIndex++;
}
As I understand it this should shifts all existing buttons up a cell. This seems to work the first three times but after that is inserts the new button into the 2nd cell a few times then the 3rd cell, then the 4th etc...
Is there a limit on how many times you can call Controls.Add(ctrl, column, row) for a given cell?
I bit stuck, what am I doing wrong?