I am using the .NET framework 4.
In my form, I have 41 text boxes.
I tried with this code:
private void ClearTextBoxes()
{
Action<Control.ControlCollection> func = null;
func = (controls) =>
{
foreach (Control control in controls)
if (control is TextBox)
(control as TextBox).Clear();
else
func(control.Controls);
};
func(Controls);
}
And this code:
private void ClearTextBoxes(Control.ControlCollection cc)
{
foreach (Control ctrl in cc)
{
TextBox tb = ctrl as TextBox;
if (tb != null)
tb.Text = String.Empty;
else
ClearTextBoxes(ctrl.Controls);
}
}
This still does not work for me.
When I tried to clean up with this code TextBoxName.Text = String.Empty;, the success of the text field was deleted, but one text field still contained 40 text fields.
How to solve this?
EDIT
I added the following:
private void btnClear_Click(object sender, EventArgs e)
{
ClearAllText(this);
}
void ClearAllText(Control con)
{
foreach (Control c in con.Controls)
{
if (c is TextBox)
((TextBox)c).Clear();
else
ClearAllText(c);
}
}
but still not working.
Edit

I used panels and a separator.
source
share