snorlax snorlax - 4 years ago 95
C# Question

How can one refresh TabContol inner controls?

First, I read this Reset all the items in a form

It was a great help until I realised all my controls are inside a

TabControl
containing itself several tabs in which there are all the common controls i.e. textbox, datetimepicker, datagrigview, etc....

Then I tried
MyTabControl.Controls.Clear()
but this deleted all tabs in the form.

How can I implement this Reset all the items in a form in a TabControl ?

Answer Source

use:

foreach (Control c in GetAll(myTabControl))
{
    ResetAllControls(c);
}

in which ResetAllControls is the method in your referenced link and

public static IEnumerable<Control> GetAll(Control control)
{
    var controls = control.Controls.Cast<Control>();
    return controls.SelectMany(ctrl => GetAll(ctrl))
                                  .Concat(controls);
}

from the accepted answer of this question.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download