المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : TableLayoutPanel Problem



C# Programming
11-12-2009, 07:50 AM
Can't work out what I'm doing wrong. When I programmatically add a button to the first cell of a table layout panel by calling 'tlp.Controls.Add(newButton, 0, 0)' it works the first three times, shifting existing controls along a cell as expected. However after the third time the same code inserts the button into the second cell a few times, then after more calls, the third etc. Examlpe code below.

Is there a limit on how many times you can call Controls.Add(ctrl, column, row) for a given cell?

private int nextIndex = 1; // used to label each button

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++;
}