title: Adding labels and other controls to a groupbox dynamically in vb.net not working?
body: <p>So I've been having problems adding labels from a record structure into a groupbox that stack below each other vertically. I could use a Flow Layout Panel but I have multiple labels I need to add from data in a record structure which I want to be able to scroll later with a vertical scrollbar as the autoscroll will only work with one panel only, and not all of them.</p>
  
  <p>For some reason the program puts only one label in, and the others don't seem to be visible even though they have been created (I used a messagebox to check). Could someone please help me to put them in, as I am fairly new to programming and need help.</p>
  
  <p>For context, the program loads 'materials' from an xml file and stores it in a record structure, then this bit of the program creates labels and radio buttons dynamically and puts it in a groupbox, so that it can be arranged manually on a pretty grid that will all become scrollable by using a scrollbar later.. Because the data I am working with is all related, and can have strings of multiple sizes (names and suppliers of materials for example) I didn't want to attempt to add whitespace to make the grid work but with a single label (not that the others would show beneath the first for some reason)</p>
  
  <p>CODE:</p>
  
  <pre><code>'sets up Labels for editing materials
      prgFunctions.loadMat()
      Dim counter As Integer
  
      Dim newMatIDLabel(numMatFile) As Label
      Dim newMatRdb(numMatFile) As RadioButton
      Dim lastPos As Integer
  
      'testing to see if materials load GET RID OF LATER
      '  For counter = 1 To numMatFile
      'ListBox1.Items.Add(materials(counter).matName)
      '  Next
  
      'create the labels with information
      For counter = 1 To numMatFile
          'ID
          newMatIDLabel(counter) = New Label
          newMatIDLabel(counter).Name = "lblMatIDNum" &amp; counter
          newMatIDLabel(counter).Text = materials(counter).matID
          newMatIDLabel(counter).Parent = gbxMaterials
  
  
          ' MsgBox(newMatIDLabel(counter).Name &amp; "  " &amp; newMatIDLabel(counter).Text)
      Next
  
      'create the checkboxes NOW RADIO BUTTONS
      For counter = 1 To numMatFile
          newMatRdb(counter) = New RadioButton
          newMatRdb(counter).Name = "chkMatSelectNum" &amp; counter
          newMatRdb(counter).Text = ""
          newMatRdb(counter).Parent = gbxMaterials
      Next
  
      'matID locations
      lastPos = 10
      For counter = 1 To numMatFile
          'SOMEHOW MOVE IT INTO THE GROUPBOX INSTEAD, as issues arise everywhere
          newMatIDLabel(counter).Location = New Point(7, lastPos + 10)
  
          lastPos = lastPos + 10
      Next
  </code></pre>