RadioButton是由数据库列表数据读出来,放到panelEx2上的,现在局部刷新,需要删除这些RadioButton,重新添加。
List<Control> removeList = new List<Control>();
for (int i = 0; i < this.panelEx2.Controls.Count; i++)
{
Control ctl = this.panelEx2.Controls[i];
if (ctl is RadioButton)
{
removeList.Add(ctl);
}
}
removeList.ForEach(ctl => this.panelEx2.Controls.Remove(ctl));
注:切忌用foreach。