I adding labels to a tablelayoutpanel from an array. The labels add no problem, but their is a huge gap between each of the labels. Did I code something incorrectly? This is my array, and adding the labels. The tablelayoutpanel is added from the GUI and is named tablelayoutpanel1
while (dr.Read())
{
labelsToAdd.Add(dr[0].ToString());
}
dr.Close();
foreach (string label in labelsToAdd)
{
Label lbl = new Label();
lbl.Name = "lbl_" + index;
lbl.Text = label;
lbl.AutoSize = true;
tableLayoutPanel1.Controls.Add(lbl, 0, rowIndex);
rowIndex++;
}
So they will add like this with all the whitespace in between them
label1
label2
Visual Sample -
From your comment:
So it looks like you should clear the rows first since your
GrowStyle = AddRows
: