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);
Comments
Leave a comment