68 464
Assignments Done
98,6%
Successfully Done
In December 2018

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?
Expert's answer
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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions