T
Tom
This is very strange: I have a Windows Form with a Panel on it. In that
panel I dynamically (at run time) create some labels, as so:
for i=1 to x
dim ctlNew as New Label()
with ctlNew
.Name="Whatever" & trim(cstr(i))
.Text=.Name
.Visible=True
... etc etc etc ...
end with
MyPanel.Controls.Add(ctlNew)
This shows up fine when the form is displayed. However, I also have a reset
button on the form, which goes thru and destroys the labels, as such:
dim ctl as Control
for each ctl in MyPanel.Controls
if typeof ctl is Label then
ctl.text=""
ctl.visible=False
ctl.Dispose()
end if
next
OK, here is the WIERD thing: The For...Each loop only seems to pick up the
EVEN or ODD numbered controls! It skips some of the controls (i.e. the odd
ones).... if I rerun the loop about three times, one right after the other,
it will finally pick up all the controls and get rid of them.
I -think- the code is correct - I even added a ctl=Nothing before and/or
after the ctl.Dispose(), but it didn't help. The For...Each loop just seems
the skip some of the label controls during its run. I am baffled ... even
though it is probably something dumb that I am doing.
Anyone got any ideas on this?
Tom
panel I dynamically (at run time) create some labels, as so:
for i=1 to x
dim ctlNew as New Label()
with ctlNew
.Name="Whatever" & trim(cstr(i))
.Text=.Name
.Visible=True
... etc etc etc ...
end with
MyPanel.Controls.Add(ctlNew)
This shows up fine when the form is displayed. However, I also have a reset
button on the form, which goes thru and destroys the labels, as such:
dim ctl as Control
for each ctl in MyPanel.Controls
if typeof ctl is Label then
ctl.text=""
ctl.visible=False
ctl.Dispose()
end if
next
OK, here is the WIERD thing: The For...Each loop only seems to pick up the
EVEN or ODD numbered controls! It skips some of the controls (i.e. the odd
ones).... if I rerun the loop about three times, one right after the other,
it will finally pick up all the controls and get rid of them.
I -think- the code is correct - I even added a ctl=Nothing before and/or
after the ctl.Dispose(), but it didn't help. The For...Each loop just seems
the skip some of the label controls during its run. I am baffled ... even
though it is probably something dumb that I am doing.
Anyone got any ideas on this?
Tom