For Each cntrl As Control In Me.Controls
If TypeOf cntrl Is Label And cntrl.Name Like "lblPosition_*" Then
cntrl.Dispose()
End If
Next
When I use the above code, it only disposes of half (exactly) of the controls I’m targeting. If I put a count in there to count the controls, it results in an accurate count, but as soon as I put the dispose() in, I only get about half of the controls disposed.
During testing I added a button that just runs the above code, and each time I press it, it still only gets exactly half of the controls.
Purpose of this code is to dispose/remove of the targeted controls in an attempt to refresh the controls added at form load.