Removing
-
Hi, I need to delete all the radiobuttons in a panel (other controls are in panel as well). This code I came up with only seems to get ride of some, but not all :o( foreach (Control control in panel_Label.Controls) { if (control is RadioButton) { control.Dispose(); } } thanks, Ron
-
Hi, I need to delete all the radiobuttons in a panel (other controls are in panel as well). This code I came up with only seems to get ride of some, but not all :o( foreach (Control control in panel_Label.Controls) { if (control is RadioButton) { control.Dispose(); } } thanks, Ron
Probably some of the radio buttons aren't direct child controls of the panel, but childs of childs (of childs ..) of the panel.?
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
-
Hi, I need to delete all the radiobuttons in a panel (other controls are in panel as well). This code I came up with only seems to get ride of some, but not all :o( foreach (Control control in panel_Label.Controls) { if (control is RadioButton) { control.Dispose(); } } thanks, Ron
try this call the method on pageload
RemoveRadioButtons(MyPanel);
here's the method...public void RemoveRadioButtons(Control parentControl) { foreach(Control childControl in parentControl.Controls) { if(childControl.HasControl()) { //Call again the RemoveRadioButtons method to iterate to childcontrols RemoveRadioButtons(childControl); } elseif(childControl is RadioButton) { parentControl.Controls.Remove(childControl); } } }
Regards, Mark -
Probably some of the radio buttons aren't direct child controls of the panel, but childs of childs (of childs ..) of the panel.?
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
Hi Rick, All radio buttons are added at run time with this code (to the same panel): RadioButton newPointer = new RadioButton(); newPointer.Size = new System.Drawing.Size(78, 16); newPointer.CheckAlign = ContentAlignment.TopLeft; newPointer.TextAlign = ContentAlignment.TopLeft; newPointer.FlatStyle = FlatStyle.Flat; newPointer.Text = pointerName; panel_Label.Controls.Add(newPointer); thanks, Ron
-
Hi Rick, All radio buttons are added at run time with this code (to the same panel): RadioButton newPointer = new RadioButton(); newPointer.Size = new System.Drawing.Size(78, 16); newPointer.CheckAlign = ContentAlignment.TopLeft; newPointer.TextAlign = ContentAlignment.TopLeft; newPointer.FlatStyle = FlatStyle.Flat; newPointer.Text = pointerName; panel_Label.Controls.Add(newPointer); thanks, Ron
myNameIsRon wrote:
Hi Rick
I'm not Rick. It's the person I cite in my signature.
myNameIsRon wrote:
All radio buttons are added at run time with this code (to the same panel):
OK, so no recursion or iteration of additional controls is needed. Try to explicitely remove the radio button from the panel before disposing it.
foreach (Control control in panel_Label.Controls)
{
if (control is RadioButton)
{
panel_Label.Controls.Remove(control);
control.Dispose();
}
}
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
-
myNameIsRon wrote:
Hi Rick
I'm not Rick. It's the person I cite in my signature.
myNameIsRon wrote:
All radio buttons are added at run time with this code (to the same panel):
OK, so no recursion or iteration of additional controls is needed. Try to explicitely remove the radio button from the panel before disposing it.
foreach (Control control in panel_Label.Controls)
{
if (control is RadioButton)
{
panel_Label.Controls.Remove(control);
control.Dispose();
}
}
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
Hi, Thanks for your help. I tried your code, but same thing is happening. If I change anthing else, it works fine: foreach (Control control in panel_Label.Controls) { if (control is RadioButton) { control.Text = "New Text"; } } Ron
-
Hi, Thanks for your help. I tried your code, but same thing is happening. If I change anthing else, it works fine: foreach (Control control in panel_Label.Controls) { if (control is RadioButton) { control.Text = "New Text"; } } Ron
Errh, should have seen it immediately. The problem is the
foreach
loop that prevents you from changing the iterated collection. Change it to afor
loop and it should work.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook