Count Checked Checkboxes in List

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • darkminos
    New Member
    • Mar 2009
    • 11

    Count Checked Checkboxes in List

    Hi,

    I have the following code

    Code:
    int countCheckState = 0
    for (int i = 0; i < CheckboxList.Count; i++)
    {
         if (CheckboxList[i].Checked) countCheckState++
         if (countCheckState == 0)
         {
              MessegeBox.Show("select any checkbox");
              return;
         }
    }

    Now, the code checks only the first checkbox and ignores the rest, while I need the code to check all the states and only if no checkboxes are selected to return "select any checkbox".
    Last edited by tlhintoq; Mar 24 '09, 05:05 PM. Reason: Indenting code to make things more obvious
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Now, the code checks only the first checkbox and ignores the rest, while I need the code to check all the states and only if no checkboxes are selected to return "select any checkbox".
    Yep. That's is a clear statement (but no question). I have edited your post to include indentation in the code. That should make the reason very clear.

    To me the implied question of your statement is "What can I do to debug this loop?"

    Put a breakpoint on line 1 and walk through the code with the F-10 key. I promise when you find it you're going to slap yourself in the head and admit it times to get some sleep.

    Comment

    • darkminos
      New Member
      • Mar 2009
      • 11

      #3
      ~Slap!
      Thanks again tlhintoq! :)

      Comment

      Working...