I am using this code to clear a form but it is throwing an error. Any help is appreciated.
public static void ClearForm(Control parent)
{
foreach (Control ctrControl in parent.Controls)
{
if (object.ReferenceEquals(ctrControl.GetType(), typeof(TextBox)))
{
((TextBox)ctrControl).Text = string.Empty;
}
else if (object.ReferenceEquals(ctrControl.GetType(), typeof(RichTextBox)))
{
((RichTextBox)ctrControl).Text = string.Empty;
}
else if (object.ReferenceEquals(ctrControl.GetType(), typeof(ComboBox)))
{
((ComboBox)ctrControl).SelectedIndex = -1;
}
else if (object.ReferenceEquals(ctrControl.GetType(), typeof(CheckBox)))
{
((CheckBox)ctrControl).Checked = false;
}
else if (object.ReferenceEquals(ctrControl.GetType(), typeof(RadioButton)))
{
((RadioButton)ctrControl).Checked = false;
}
if (ctrControl.Controls.Count > 0)
{
ClearForm(ctrControl);
}
}
}