I know that this question is very old, but someone could take this as useful thing.
First of all note that petchirajan answer is good, but if you have at least one existent row (titles, for example) and you want to continue the list using height set using visual editor, without modify the code, you can use this:
private void AddItem(string address, string contactNum, string email )
{
//get a reference to the previous existent
RowStyle temp = panel.RowStyles[panel.RowCount - 1];
//increase panel rows count by one
panel.RowCount++;
//add a new RowStyle as a copy of the previous one
panel.RowStyles.Add(new RowStyle(temp.SizeType, temp.Height));
//add your three controls
panel.Controls.Add(new Label() {Text = address}, 0, panel.RowCount - 1);
panel.Controls.Add(new Label() { Text = contactNum }, 1, panel.RowCount - 1);
panel.Controls.Add(new Label() { Text = email }, 2, panel.RowCount - 1);
}
If you prefer generic method for a generic table:
private void AddRowToPanel(TableLayoutPanel panel, string[] rowElements)
{
if (panel.ColumnCount != rowElements.Length)
throw new Exception("Elements number doesn't match!");
//get a reference to the previous existent row
RowStyle temp = panel.RowStyles[panel.RowCount - 1];
//increase panel rows count by one
panel.RowCount++;
//add a new RowStyle as a copy of the previous one
panel.RowStyles.Add(new RowStyle(temp.SizeType, temp.Height));
//add the control
for (int i = 0; i < rowElements.Length; i++)
{
panel.Controls.Add(new Label() { Text = rowElements[i] }, i, panel.RowCount - 1);
}
}
You can do this also using a Collection instead of an array using
Try the below code,
in foreach example:
I know that this question is very old, but someone could take this as useful thing.
First of all note that petchirajan answer is good, but if you have at least one existent row (titles, for example) and you want to continue the list using height set using visual editor, without modify the code, you can use this:
If you prefer generic method for a generic table:
You can do this also using a Collection instead of an array using
Hope it helps.