I have a groupbox which contains 10+ checkboxes. I would like to build a string that concatenates the Checkbox.Text of all the checkboxes which are checked.
Of course anytime the checked state changes for any of the checkboxes it will need to rebuild the string. How can I go about doing this?
Note: This needs to happen on the fly as checkboxes are checked/unchecked.
This is the idea I had going, but I feel like that there is a better way to do this - and also I'm not sure how I am going to remove the strings when an item is unchecked.
Any thoughts?
private void CheckBox_CheckedChanged(System.Object sender, System.EventArgs e)
{
if (((CheckBox)sender).Checked)
{
switch (((CheckBox)sender).Name)
{
case "CheckBox1":
sb = sb + "This is checkbox 1." + "\n";
break;
case "CheckBox2":
sb = sb + "This is checkbox 2." + "\n";
break;
case "CheckBox3":
sb = sb + "This is checkbox 3." + "\n";
break;
case "CheckBox4":
sb = sb + "This is checkbox 4." + "\n";
break;
case "CheckBox5":
sb = sb + "This is checkbox 5." + "\n";
break;
case "CheckBox6":
sb = sb + "This is checkbox 6." + "\n";
break;
case "CheckBox7":
sb = sb + "This is checkbox 7." + "\n";
break;
case "CheckBox8":
sb = sb + "This is checkbox 8." + "\n";
break;
case "CheckBox9":
sb = sb + "This is checkbox 9." + "\n";
break;
case "CheckBox10":
sb = sb + "This is checkbox 10." + "\n";
break;
}
}
else
{
}
}