Dynamically add row to Table Layout Panel

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Dynamically add row to Table Layout Panel



I am trying to add rows with textboxes dynamically to a Table Layout Panel, and the code I have here adds the row, but the spacing is off. When it adds the row it is smaller than the row before. Any ideas on how to add a row that is also formatted the same as the previous? Thanks.


int A = 1;
public TextBox AddNewTextBox()

TextBox txt = new TextBox();
this.Controls.Add(txt);
txt.Top = A * 28;
txt.Left = 15;
txt.Text = " ";
A = A + 1;
return txt;


public void DeleteTextBox()

if (A >= 2)

tableLayoutPanel1.Controls.RemoveAt(A);
A--;


private void AddRowBTN_Click(object sender, EventArgs e)

this.tableLayoutPanel1.RowCount++;

this.tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 28.57143F));
tableLayoutPanel1.Controls.Add(AddNewTextBox());
if(A >= 10)

this.tableLayoutPanel1.Size = new Size((282),(207*2)) ;


private void button8_Click(object sender, EventArgs e)

DeleteTextBox();




1 Answer
1



Set the AutoSize property of tableLayoutPanel to true or Use following code on form Load or inside the constructor of form


tableLayoutPanel1.AutoSize = true;





That worked! Thanks
– landino95
Aug 10 at 20:28






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard