Tech
Forums
Jobs
Books
Events
Live
Interviews Prep
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
2
Reply
Removing all buttons from form
Swatto
Jan 31 2015 9:49 AM
548
Reply
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);
}
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
2
)
Next Recommended Forum
SUM and UNION for sum two field from table
How to Add Multiple Crystal Reports To CrystalReport Viewer