TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Charles Morissette
NA
29
42.9k
Foreach skips
Mar 24 2011 11:10 AM
I'm doing a foreach loop, it's looking through the controls in splitContainer1.Panel2 in one of my forms.
The purpose is to bring back all the controls from panel2, and then check if they are a groupbox. If they are, it then deletes it. My problem is it seems to only delete some of them, and leave others there.
I've added a list to check if it detects all the groupboxes, if I make the code to delete a note rather then code it will detect every groupbox. The moment I try to delete them again, it detects a different amount.
These groupboxes are dynamically created in run time, and need to be removed during the program's use.
List<string> BoxxCheck = new List<string>();
List<string> ActualBoxes = new List<string>();
Parts = 0;
foreach (Control Boxx in this.splitContainer1.Panel2.Controls)
{
if (Boxx is GroupBox)
{
BoxxCheck.Add(Boxx.Name.ToString());
//splitContainer1.Panel2.Controls.Remove(Boxx);
}
}
lblTest.Text = string.Join(",", BoxxCheck);
Is my current code.
Reply
Answers (
3
)
How do you implement thread synchronization in C#
Need help with ConsoleCursor please