我需要有控制权来提供下一个功能:
但我对插入有一些问题。有时它会正确插入,但通常不会。
tableLayoutPanel1.SuspendLayout();
tableLayoutPanel1.RowCount++;
tableLayoutPanel1.RowStyles.Insert(tableLayoutPanel1.RowCount - 1, new RowStyle(SizeType.AutoSize));
var control = CreateControl();
tableLayoutPanel1.Controls.Add(control,0,tableLayoutPanel1.RowCount - 1);
tableLayoutPanel1.ResumeLayout();
我做错了什么?
错误示例:
答案 0 :(得分:0)
假设Add Button对象被称为btnAdd,我认为这应该有效 -
tableLayoutPanel1.SuspendLayout();
tableLayoutPanel1.RowCount++;
tableLayoutPanel1.RowStyles.Insert(tableLayoutPanel1.RowCount - 1, new RowStyle(SizeType.AutoSize));
tableLayoutPanel1.SetRow(btnAdd, tableLayoutPanel1.RowCount - 1);
var control = CreateControl();
tableLayoutPanel1.Controls.Add(control, 0, tableLayoutPanel1.RowCount - 2);
tableLayoutPanel1.ResumeLayout();