Reputation: 15
I need simple logic iteration but many item... this is my code
byte[] nc1 = new byte[40];
nc1 = ChekSt(36, "192.168.2.55", 38, 40);
//I need to iterate 40 times so my 40 checkbox can be updated
switch (nc1[0])
{
case 1: checkBox1.Checked = false; break;
case 2: checkBox1.Checked = true; checkBox1.CheckState = CheckState.Indeterminate; break;
case 3: checkBox1.Checked = true; checkBox1.CheckState = CheckState.Checked; break;
}
i have checkBox1, checkBox2, checkBox3... to checkBox40
i need someting like checkBox(i).checked = true;
so don't have to write my code 40 times
anyone have idea...?
Upvotes: 0
Views: 183
Reputation: 29000
try with this code
foreach (CheckBox checkbox in yourPanelContainer.Controls.OfType<CheckBox>())
{
checkbox.Checked = true;
}
Upvotes: 1
Reputation: 9670
Put the check boxes in an array or a List so that you can manipulate them in a set-based manner.
For example
var list = new List<CheckBox>();
list.Add(checkBox1);
list.Add(checkBox2);
list.Add(checkBox3);
list[2].Checked = true;
Upvotes: 1