Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add Row Dynamically in TableLayoutPanel

enter image description here

I want to add these entries dynamically row by row in TableLayoutPanel in Windows Form in c#

How can I do that?

like image 737
akash Avatar asked Mar 15 '14 06:03

akash


1 Answers

Try the below code,

// TableLayoutPanel Initialization TableLayoutPanel panel = new TableLayoutPanel(); panel.ColumnCount = 3; panel.RowCount = 1; panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 40F)); panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 30F)); panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 30F)); panel.RowStyles.Add(new RowStyle(SizeType.Absolute, 50F)); panel.Controls.Add(new Label() { Text = "Address" }, 1, 0); panel.Controls.Add(new Label() { Text = "Contact No" }, 2, 0); panel.Controls.Add(new Label() { Text = "Email ID" }, 3, 0);  // For Add New Row (Loop this code for add multiple rows) panel.RowCount = panel.RowCount + 1; panel.RowStyles.Add(new RowStyle(SizeType.Absolute, 50F)); panel.Controls.Add(new Label() { Text = "Street, City, State" }, 1, panel.RowCount-1); panel.Controls.Add(new Label() { Text = "888888888888" }, 2, panel.RowCount-1); panel.Controls.Add(new Label() { Text = "[email protected]" }, 3, panel.RowCount-1); 
like image 105
petchirajan Avatar answered Sep 22 '22 04:09

petchirajan