Dispose all usercontrols...

lidds

Well-known member
Joined
Oct 19, 2004
Messages
122
Programming Experience
Beginner
I had a number of userControls added to a tableLayout, what I want to do is dispose of all userControls however if I use the following code it only seems to dispose of the first userControl and not the rest:

VB.NET:
            For Each myControl As userDisplaySet In Me.tableDisplaySet.Controls
                ' Closes control
                myControl.Dispose()
            Next

Thanks

Simon
 
You get a variation of "collection changed during loop" problem. You can use the common solution looping by index in reverse.
 
Back
Top