I have some controls that are built at run time. There is a groupbox with 3 radio buttons with the CheckedChanged event used to fill a control with a various number of groupboxes with each groupbox containing 4 more radio buttons. Since there is a various number of groupboxes inside this panel, I am trying to dispose of any groupbox that is currently in the panel, then I will rebuild with the ones I need to display. The problem is I am using a foreach loop to do so and for soem reason it only disposes of every other one. so if I were to have 8 groupboxes the 1st, 3rd, 5th and 7th would be disposed of but the 2nd,4th 6th and 8th would still show.
Here is the code I am using. I commented part of it out hoping to resolve the issue with no luck.
public void ClearRadios()
{
foreach (Control control in pnlDimensions.Controls)
{
// if (control.GetType() == typeof(GroupBox))
// {
control.Dispose();
// }
}
}
TIA for any help