Thea Burger's Blog

Wouldn't you like to know...

News

Photo's!!!

About me

I'm Reading: General Blogs

I'm Reading: Technical Blogs

Browse by Tags

All Tags » C# (RSS)
Controls.Remove index change
Came across something now which was quite funny... I dynamically add controls to my form, and I also need the option to remove them again. So at first I did this, which seemed logic as it is exactly how I add them: foreach (Control c in this .Controls) { if (c.GetType() == typeof (TextBox)) { this .Controls.Remove(c); } } But this only removed every second textbox! At first I was dumbstruck, but then found out that when you remove a Control from the ControlCollection, subsequent controls are moved...
Posted: Aug 14 2006, 09:47 PM by Thea Burger | with 3 comment(s)
Filed under: ,