Guest Nightmare Posted November 11, 2002 Posted November 11, 2002 Hey there. I'm wondering why this code is not working for me: Dim pic As Control For Each pic In panContainer.Controls panContainer.Controls.Remove(pic) Next pic It seems as if only some of the pictures within panContainer are being removed. If I repeated this code again a few more of the pictures in panContainer will be removed. I have no idea what is going on. How can I completely remove any controls which might exist within panContainer? Any hints you could give me would be appreciated :cool: Quote
*Gurus* divil Posted November 11, 2002 *Gurus* Posted November 11, 2002 You can't change the contents of a collection while enumerating it. Instead, try something like this: Dim intIndex As Integer For intIndex = Panel1.Controls.Count - 1 To 0 Step -1 Panel1.Controls.Remove(Panel1.Controls(intIndex)) Next Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Guest Nightmare Posted November 12, 2002 Posted November 12, 2002 Thank you Duuuuh! I don't know what I was thinking. Works perfectly now. Thanx a lot Divil. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.