Q: Progammically change multiple buttons with for loop C# Im trying to do something like this:
list<int> listName = new list<int>();

for(int i; i <= listName[0];i++)
{
    button(i).Enabled = false;
}

... to disable all buttons from 1 to i.
What would be the best way of doing this?
Thanks. 

A: There are a few ways to bulk modify controls.
Example 1 (putting them all in a list)
List<Button> buttonsToDisable = new List<Button>()
{
    button1, 
    button2
};

foreach (var button in buttonsToDisable)
{
    button.Enabled = false;
}


Example 2 (putting them in the same container then iterating over the controls in that container)
foreach(var button in groupBox1.Controls.OfType<Button>())
{
    button.Enabled = false;
}


Example 3 (subfixing your controls with an id)
List<int> buttonSubfixId = new List<int>()
{
    1,
    2
};

foreach (var id in buttonSubfixId)
{
    var controls = this.Controls.Find("button" + id.ToString(), true).OfType<Button>();

    if (controls.Count()>0)
    {
        foreach (var button in controls)
        {
            button.Enabled = false;
        }
    }
}

