Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

multiple checkBox selection.

Status
Not open for further replies.

rstum2005

Programmer
Jun 9, 2005
117
0
0
US
I would like to Check multiple checkBoxs and do functions based on what series of checkBoxes were Checked. What would be the best way to do this insted of a bunch of if/else statements?

Thanks

if/else Example:

if (checkBox1.Checked==true&&checkBox2.Checked==true)
{

}
 
You could try toggling 'flag' bits then do a switch/case

something like this..
Code:
unsigned int flags = 0x0;

if(Checkbox1.Checked == true)
    flags &= 0x01;
if(Checkbox2.Checked == true)
    flags &= 0x02;
if(Checkbox3.Checked == true)
    flags &= 0x04;
...
switch(flags)
{
    case 0x01:
        break;
    case 0x02:
        break;
    case 0x03:
        break;
    case 0x04:
        break;
    default:
        break;
}

Just a thought. Also, you could give each one of the 'flag' bits a meaningful name using enum's or #define them
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top