Hi sir/ ma'am! Regarding to Visual C#, our instructor want our program to perform the action. Using multiple checkbox and display the assigned values (if more than one checkbox is checked) of the checkbox in a single textbox. What should i do?
private void checkBoxes_CheckedChanged(object sender, EventArgs e)
{
string values = string.Empty;
foreach (var checkBox in this.Controls.OfType<CheckBox>())
{
if (checkBox.Checked)
{
values += string.Format("{0}, ", checkBox.Text);
}
}
if (!string.IsNullOrEmpty(values))
{
values = values.Remove(values.Length - 2);
}
if (values.Split(',').Length > 1)
{
textBox1.Text = values;
}
else
{
textBox1.Clear();
}
}
and register all events "CheckedChanged" of checkbox using method above:
this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBoxes_CheckedChanged);
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
C#