On Mon, 25 Jun 2007 18:07:56 -0700, Bill Gower <bi*******@charter.net
wrote:
[...]
What is the easiest and cleanest way to go through all the checkboxes
and if
the value is true concatenate the enum values together to pass to the
function?
I will refrain from making absolute claims of "easiest" or "cleanest", but
it seems to me that you could take advantage of the Tag property of the
controls and group them together with a group box. Then your code would
just enumerate all of the controls in the group box, parsing each one's
Tag if it's checked, and or-ing that into your enumeration.
For example:
MyEnum myenum = MyEnum.None;
foreach (CheckBox chk in groupBox1.Controls)
{
if (chk.Checked)
{
myenum |= (MyEnum)Enum.Parse(typeof(MyEnum),
chk.Tag.ToString());
}
}
If the Name or Text property of the checkboxes just happened to coincide
with the names of the enum values, you could even just use either of those
properties instead as appropriate.
Pete