E
esebastian
Hello Everyone,
I would just like some advice to make sure i am doing what i want to
do the right way because i don't think i am.
I have a form that contains checkboxes. The checkboxes are created
dynamically from a database. When the user presses the submit button i
want to loop through all of the checkboxes and fill an IList with the
text from the checkboxes that are checked. Here is how i do it.. it
looks a bit convoluted , is there a better way of doing this?
Thanks in advance,
foreach (Object obj in this.Controls)
{
if (obj.GetType() == typeof(GroupBox))
{
GroupBox tempGroupBox = (GroupBox)obj;
foreach (Object tmpObj in
tempGroupBox.Controls)
{
if (tmpObj.GetType() == typeof(CheckBox))
{
CheckBox chk = (CheckBox)tmpObj;
if (chk.Checked)
{
imageList.Add(chk.Text);
}
}
}
}
}
I would just like some advice to make sure i am doing what i want to
do the right way because i don't think i am.
I have a form that contains checkboxes. The checkboxes are created
dynamically from a database. When the user presses the submit button i
want to loop through all of the checkboxes and fill an IList with the
text from the checkboxes that are checked. Here is how i do it.. it
looks a bit convoluted , is there a better way of doing this?
Thanks in advance,
foreach (Object obj in this.Controls)
{
if (obj.GetType() == typeof(GroupBox))
{
GroupBox tempGroupBox = (GroupBox)obj;
foreach (Object tmpObj in
tempGroupBox.Controls)
{
if (tmpObj.GetType() == typeof(CheckBox))
{
CheckBox chk = (CheckBox)tmpObj;
if (chk.Checked)
{
imageList.Add(chk.Text);
}
}
}
}
}