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
Swatto
NA
23
11k
Removing all buttons from form
Jan 31 2015 9:49 AM
Hello all,
Why did one method work but the other did not and produce weird results?
I was trying to remove all controls of type button from a form. I tried two methods:
This worked:
public void ClearButtons()
{
for (int i = 0; i < this.Controls.Count; i++)
{
if (Controls[i] is Button)
{
Controls.RemoveAt(i);
i--;
}
}
}
Didn't work (I got weird results, some buttons would stay on the form):
foreach(Control control in Controls)
{
if (control is Button)
Controls.Remove(control);
}
Reply
Answers (
2
)
SUM and UNION for sum two field from table
How to Add Multiple Crystal Reports To CrystalReport Viewer