I'm attempting to clear all the checkboxes and textboxes in the first panel of my splitcontainer but I'm having no luck as nothing seems to happen.
private void clearSettingsBtn_Click(object sender, EventArgs e)
{
foreach (Control c in splitContainer1.Panel1.Controls)
{
if (c is CheckBox)
{
((CheckBox)c).Checked = false;
}
else if (c is TextBox)
{
((TextBox)c).Clear();
}
}
}
Have I missed something?
Pravesh Singh
23-Dec-2013Actually your code is pretty OK, there should be another problem like wrong panel or more likely there would be another container in your panel, like a GroupBox, which in that case (another container) you should iterate through that container.
In case you have a container inside the panel a simple code could be like this:
But if you want to write a more general code, you should check for each container, i.e. GroupBox, Panel etc.