I have found a temp solution to the problem, although there must be a
better way. I added enlosed the For...Next in another loop and cycle
through it once more.
For i as integer = 0 to 1
For each ctrl as Control In Me.Controls()
If Not ctrl is Nothing
If ctrl.gettype is gettype(Label)
ctrl.dispose
debug.writeline(mrk.name & " Removed")
End If
End If
Next
Next
This removes all controls, but it shouldn't have to be done this way.
Charlie Brown wrote:
For i as integer = 0 to 4
Dim mrk as new Label
lbl.name = "shiftmrk" & i
me.controls.add(mrk)
Debug.writeline(mrk.name & " Added")
Next
For each ctrl as Control In Me.Controls()
If Not ctrl is Nothing
If ctrl.gettype is gettype(Label)
ctrl.dispose
debug.writeline(mrk.name & " Removed")
End If
End If
Next
Typed this by hand quick, but my code is the same.
Brendan Green wrote:
Post your code for both adding the controls, and listing them by name.
"Charlie Brown" <cb****@duclaw.comwrote in message
news:11**********************@j8g2000cwa.googlegro ups.com...
>I am adding controls to the Forms controls collection at run-time.
Then when I loop through the controls and list them by name, I am
missing half my controls. Is there a workaround?
>
Debugger output while adding
>
shiftmrk0 Added
shiftmrk1 Added
shiftmrk2 Added
shiftmrk3 Added
shiftmrk4 Added
>
Debugger output while looping through the forms controls() collection
>
shiftmrk0
shiftmrk2
shiftmrk4
>
All controls are children of the Form, no panels or tab controls.
>