I´m trying to remove textbox controls from a panel in a event Button click:
private void button2_Click(object sender, EventArgs e)
{
panel1.Controls.OfType<TextBox>().ToList().Clear();
}
but it doesn´t work
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The reason why your approach is not working, is that you are creating a new List, not connected to the panel (your
ToListcall), then clearing that list, effectively doing nothing.You need to remove each item on the
Controlscollection directly: