I am trying to dynamically add checkboxes to a panel depending on if a file exists. My code is:
While d1 <= d2
If File.Exists("C:\bnb\" & m1 & "-" & d1 & "-" & y1) = False Then
rm1CheckBoxes(rm1I) = New CheckBox()
rm2CheckBoxes(rm2I) = New CheckBox()
rm1CheckBoxes(rm1I).Location = New Point(20, rm1y)
rm2CheckBoxes(rm2I).Location = New Point(60, rm2y)
rm1y = rm1y + 20
rm2y = rm2y + 20
MessageBox.Show(pnlResults.Controls.Count())
pnlResults.Controls.Add(rm1CheckBoxes(rm1I))
pnlResults.Controls.Add(rm2CheckBoxes(rm2I))
rm1I = rm1I + 1
rm2I = rm2I + 1
d1 = d1 + 1
End If
End While
But only the first pnlResults.Controls.Add() actually shows up in my form. If I reverse the two calls or comment out the first one, then I get x boxes at 60,rm2y, as is I get x boxes at 20,rm1y. I tried changing the second point to a constant 60,60, and that one checkbox did appear. I am just completely lost as to why only half of my checkboxes show up. I tried putting an Application.DoEvents call at the end of the if, but that didn't fix the problem. Any help would be greatly appreciated.