Код: Выделить всё
public void DynamicObjects(int countRow)
{
tableLayout.RowCount = countRow;
tableLayout.ColumnCount = 2;
for (int i = 0; i < countRow; i++)
{
Label lblTitle = new Label();
lblTitle.Text = i + "box";
lblTitle.TextAlign = ContentAlignment.MiddleCenter;
tableLayout.Controls.Add(lblTitle, 0, i);
TextBox txtValue = new TextBox();
txtValue.Text = "2";
txtValue.Name = "txt_numberSabad" + i+1;
tableLayout.Controls.Add(txtValue, 1, i);
}
}
Код: Выделить всё
private void Form_load(object sender, EventArgs e)
{
DynamicObjects(5);
TextBox txt = (TextBox)(tableLayout.Controls["txt_numberSabad"+3]);
txt.Text = "new text for texBox";
}
System.NullReferenceException: ссылка на объект не установлена на экземпляр объекта
Подробнее здесь: https://stackoverflow.com/questions/792 ... -dynamic-c
Мобильная версия