Answer to Question #61277 in C# for Christian

Question #61277
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?
1
Expert's answer
2016-08-15T08:18:04-0400
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS