Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Clearing a portion of a Form
Message
 
To
10/04/2009 16:08:55
General information
Forum:
ASP.NET
Category:
Forms
Environment versions
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Application:
Desktop
Miscellaneous
Thread ID:
01394032
Message ID:
01394238
Views:
38
>Thought you might like to see the code I am using
>
>//Clear previously placed controls
> foreach (Control c in this.Controls)
> {
> if ( (string)c.Tag == "removable")
> {
> this.Controls.Remove(c);
> }
> }

You can't use a foreach and remove controls (or anything from a collection, for that matter). It changes the items in the list and you'll have problems like you're seeing. Use a for loop instead and loop from the last element to the first.
-Paul

RCS Solutions, Inc.
Blog
Twitter
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform