I’m trying to create a list of labels and textboxes. No errors but they aren’t rendering on the form. I have confirmed my loop have values
Private Sub AddLabels_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'MsgBox(strNumberOfLabels + " " + strOrderNum)
TableLayoutPanel1.AutoSize = True
TableLayoutPanel1.Visible = False
TableLayoutPanel1.SuspendLayout()
For i As Integer = 0 To strNumberOfLabels
'MsgBox(i)
Dim txtBox As New TextBox
Dim txtLabel As New Label
txtLabel.Text = "Label " + i
txtBox.Name = "txt" + i
TableLayoutPanel1.Controls.Add(txtLabel)
txtLabel.Show()
txtBox.Show()
TableLayoutPanel1.ResumeLayout()
TableLayoutPanel1.Visible = True
Next
End Sub
Try using the other
Addoverload, which specifies which column and row the control should go into:This is not necessary:
This should be moved outside of the loop:
The
txtBoxcontrol is never being added to theTableLayoutPanelcontrol or the form.I don’t think it’s necessary to make your TableLayoutPanel visible or invisible during the
OnLoadprocedure, the form isn’t visible yet.The only other thing to confirm is the value of
strNumberOfLabels. I’m suspecting it’s zero.