By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,264 Members | 1,763 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,264 IT Pros & Developers. It's quick & easy.

Count Checked Checkboxes in List

P: 11
Hi,

I have the following code

Expand|Select|Wrap|Line Numbers
  1. int countCheckState = 0
  2. for (int i = 0; i < CheckboxList.Count; i++)
  3. {
  4.      if (CheckboxList[i].Checked) countCheckState++
  5.      if (countCheckState == 0)
  6.      {
  7.           MessegeBox.Show("select any checkbox");
  8.           return;
  9.      }
  10. }
  11.  

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".
Mar 24 '09 #1
Share this Question
Share on Google+
2 Replies


tlhintoq
Expert 2.5K+
P: 3,525
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.
Mar 24 '09 #2

P: 11
~Slap!
Thanks again tlhintoq! :)
Mar 24 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.