I\'m building a flow layout panel whose each control represents for a room. I want to reload all room by removing all controls in the panel and adding new controls.
I us
That's because you are removing the controls from the same list you are iterating. Try something like this
List listControls = flowLayoutPanel.Controls.ToList();
foreach (Control control in listControls)
{
flowLayoutPanel.Controls.Remove(control);
control.Dispose();
}
Maybe not like that, but you get the idea. Get them in a list, then remove them.