I do remember seeing someone ask something along these lines a while ago but I did a search and couldn\'t find anything.
I\'m trying to come up with the cleanest wa
The above solutions seem to ignore nested controls.
A recursive function may be required such as:
public void ClearControl(Control control)
{
TextBox tb = control as TextBox;
if (tb != null)
{
tb.Text = String.Empty;
}
// repeat for combobox, listbox, checkbox and any other controls you want to clear
if (control.HasChildren)
{
foreach(Control child in control.Controls)
{
ClearControl(child)
}
}
}
You don't want to just clear the Text property without checking the controls type.
Implementing an interface, such as IClearable (as suggested by Bill K), on a set of derived controls would cut down the length of this function, but require more work on each control.