Amund

Amund

  • NA
  • 8
  • 32.1k

Multiple checkboxes C#

Dec 17 2010 3:37 AM
Hi,

I was wondering if my way of checking which combination of checkbox' that are checked are extremly unefficient? I have previously done it like this:
Any improving suggestion on how to iterate through checkboxes to find which combination that is checked?

            //If no heuristics is active
            if (checkboxvalues.voyageCutCheckBox == 0)
            if (checkboxvalues.costEffectivenessCheckBox == 0)
            if (checkboxvalues.accWaitingCheckBox == 0)
            if (checkboxvalues.ballastCutCheckBox == 0)
            {
              
            }

            //If only voyageCutCheckBox is active
            if (checkboxvalues.voyageCutCheckBox == 1)
            if (checkboxvalues.costEffectivenessCheckBox == 0)
            if (checkboxvalues.accWaitingCheckBox == 0)
            if (checkboxvalues.ballastCutCheckBox == 0)
            {
            }           

            //If only costEffectivenessCheckBox is active
            if (checkboxvalues.voyageCutCheckBox == 0)
            if (checkboxvalues.costEffectivenessCheckBox == 1)
            if (checkboxvalues.accWaitingCheckBox == 0)
            if (checkboxvalues.ballastCutCheckBox == 0)
            {
              
            }

            //If only accWaitingCheckBox is active
            if (checkboxvalues.voyageCutCheckBox == 0)
            if (checkboxvalues.costEffectivenessCheckBox == 0)
            if (checkboxvalues.accWaitingCheckBox == 1)
            if (checkboxvalues.ballastCutCheckBox == 0)
            {
              
            }

            //If only accWaitingCheckBox is active //
            if (checkboxvalues.voyageCutCheckBox == 0)
            if (checkboxvalues.costEffectivenessCheckBox == 0)
            if (checkboxvalues.accWaitingCheckBox == 0)
            if (checkboxvalues.ballastCutCheckBox == 1)
            {
               
            }

            //If voyageCutCheckBox and costEffectivenessCheckBox is active
            if (checkboxvalues.voyageCutCheckBox == 1)
            if (checkboxvalues.costEffectivenessCheckBox == 1)
            if (checkboxvalues.accWaitingCheckBox == 0)
            if (checkboxvalues.ballastCutCheckBox == 0)
            {
              
            }

            //If voyageCutCheckBox and accWaitingCheckBox is active
            if (checkboxvalues.voyageCutCheckBox == 1)
            if (checkboxvalues.costEffectivenessCheckBox == 0)
            if (checkboxvalues.accWaitingCheckBox == 1)
            if (checkboxvalues.ballastCutCheckBox == 0)
            {
              
            }

            //If voyageCutCheckBox and ballastCutCheckBox is active
            if (checkboxvalues.voyageCutCheckBox == 1)
            if (checkboxvalues.costEffectivenessCheckBox == 0)
            if (checkboxvalues.accWaitingCheckBox == 0)
            if (checkboxvalues.ballastCutCheckBox == 1)
            {
               
            }

            //If costEffectivenessCheckBox and accWaitingCheckBox is active
            if (checkboxvalues.voyageCutCheckBox == 0)
            if (checkboxvalues.costEffectivenessCheckBox == 1)
            if (checkboxvalues.accWaitingCheckBox == 1)
            if (checkboxvalues.ballastCutCheckBox == 0)
            {
               
            }

            //If costEffectivenessCheckBox and ballastCutCheckBox is active
            if (checkboxvalues.voyageCutCheckBox == 0)
            if (checkboxvalues.costEffectivenessCheckBox == 1)
            if (checkboxvalues.accWaitingCheckBox == 0)
            if (checkboxvalues.ballastCutCheckBox == 1)
            {
                i
            }

            //If accWaitingCheckBox and ballastCutCheckBox is active
            if (checkboxvalues.voyageCutCheckBox == 0)
            if (checkboxvalues.costEffectivenessCheckBox == 0)
            if (checkboxvalues.accWaitingCheckBox == 1)
            if (checkboxvalues.ballastCutCheckBox == 1)
            {
               
            }

            //If voyageCutCheckBox, costEffectivenessCheckBox and accWaitingCheckBox is active
            if (checkboxvalues.voyageCutCheckBox == 1)
            if (checkboxvalues.costEffectivenessCheckBox == 1)
            if (checkboxvalues.accWaitingCheckBox == 1)
            if (checkboxvalues.ballastCutCheckBox == 0)
            {
              
            }

            //If voyageCutCheckBox, costEffectivenessCheckBox and ballastCutCheckBox is active
            if (checkboxvalues.voyageCutCheckBox == 1)
            if (checkboxvalues.costEffectivenessCheckBox == 1)
            if (checkboxvalues.accWaitingCheckBox == 0)
            if (checkboxvalues.ballastCutCheckBox == 1)
            {
              
            }

            //If voyageCutCheckBox, accWaitingCheckBox and ballastCutCheckBox is active
            if (checkboxvalues.voyageCutCheckBox == 1)
            if (checkboxvalues.costEffectivenessCheckBox == 0)
            if (checkboxvalues.accWaitingCheckBox == 1)
            if (checkboxvalues.ballastCutCheckBox == 1)
            {
               
            }

            //If voyageCutCheckBox, costEffectivenessCheckBox, accWaitingCheckBox and ballastCutCheckBox is active
            if (checkboxvalues.voyageCutCheckBox == 0)
            if (checkboxvalues.costEffectivenessCheckBox == 1)
            if (checkboxvalues.accWaitingCheckBox == 1)
            if (checkboxvalues.ballastCutCheckBox == 1)
            {
               
            }
           
            //If voyageCutCheckBox, costEffectivenessCheckBox, accWaitingCheckBox and ballastCutCheckBox is active
            if (checkboxvalues.voyageCutCheckBox == 1)
            if (checkboxvalues.costEffectivenessCheckBox == 1)
            if (checkboxvalues.accWaitingCheckBox == 1)
            if (checkboxvalues.ballastCutCheckBox == 1)
            {
            }


Answers (11)