Here's the method I use for this type of thing (using yours as an
example):
ActionAll<CheckBox>(this, delegate (CheckBox box) {box.Enabled =
false;});
Very useful; the <Tallows you to restrict it to a given category
(class) of Control, and the root allows you to limit the scope.
Marc
/// <summary>
/// Applies an action to all controls of type T in a tree
/// </summary>
public static void ActionAll<T>(Control root, Action<T>
action) where T : Control
{
if (root == null) throw new ArgumentNullException("root");
if (action == null) throw new
ArgumentNullException("action");
Queue<Controlcontrols = new Queue<Control>();
controls.Enqueue(root);
while (controls.Count 0) // recurse
{
Control control = controls.Dequeue();
foreach (Control child in control.Controls)
{
controls.Enqueue(child);
}
T item = control as T;
if (item != null) // is a T
{
action(item);
}
}
}
<ma******@gmail.comwrote in message
news:11**********************@n76g2000hsh.googlegr oups.com...
Developers,
Is there any way to disable all checkboxes on a form? I have a form
with 160 checkboxes and I want to be able to disable all of them.
Is
there a way I can do something like this:
for (int i = 0; i < 160; i++)
{
string checkbox = "checkBox" + i.toString();
(Cast)checkbox.enabled = false;
}
Thanks,
Eric