private CheckBox[] checkBoxes;
private void Form1_Load(object sender, EventArgs e)
{
// Create the CheckBox array only once the controls have been created.
checkBoxes = new[] { checkBox1, checkBox2, checkBox3, checkBox4, checkBox5, checkBox6 };
// Register the handler for the Checked event. This can be done in the designer instead.
foreach (var checkBox in checkBoxes)
{
checkBox.CheckedChanged += CheckBoxes_CheckedChanged;
}
}
private void CheckBoxes_CheckedChanged(object sender, EventArgs e)
{
if (checkBoxes.Count(cb => cb.Checked) == 3)
{
foreach (var checkBox in checkBoxes)
{
// Enable a field if and only if it is...
private CheckBox[] checkBoxes;
private void Form1_Load(object sender, EventArgs e)
{
// Create the CheckBox array only once the controls have been created.
checkBoxes = new[] { checkBox1, checkBox2, checkBox3, checkBox4, checkBox5, checkBox6 };
// Register the handler for the Checked event. This can be done in the designer instead.
foreach (var checkBox in checkBoxes)
{
checkBox.CheckedChanged += CheckBoxes_CheckedChanged;
}
}
private void CheckBoxes_CheckedChanged(object sender, EventArgs e)
{
if (checkBoxes.Count(cb => cb.Checked) == 3)
{
foreach (var checkBox in checkBoxes)
{
// Enable a field if and only if it is checked.
checkBox.Enabled = checkBox.Checked;
}
}
else
{
foreach (var checkBox in checkBoxes)
{
// Enable all fields.
checkBox.Enabled = true;
}
}
}
CheckBoxes
to a Panel
and get them from there on deamnd.var limited = checkBoxes.Count(cb => cb.Checked) == 3;
foreach (var checkBox in checkBoxes)
{
// Enable if not limited, else disable not checked
checkBox.Enabled = !limited || checkBox.Checked;
}
the problem is in limiting the boxes to 3 choices and sending them to the "data" page.
That's two unrelated things so it's not THE problem. You asked a question and we have answered that. If you have a new question on a different subject then start a new thread for that containing all and only the information relevant to that. As for this question, you have your solution so go ahead and use it. Why are you restating the problem like you haven't even read what we wrote?
Maybe our OP is hoping that we would architect a solution for them in our zeal to help.