473,387 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Unchecking a check all checkbox.

Hey there everyone, this is my first post so be nice :-) I have wrote quite a bit so the actual question is written out at the end if you want to skip on and see if you can answer it without the rest of the info.

I'm a hobbiest programmer and have taken up the project of writing a savestate editor - if you don't know what that is it's not really important - but I am having a bit of trouble with some code and google isn't turning up the answer although I think it may be my search terms rather than it not being asked before so appologise if this has already been asked many a time, I have done a search!

I have got a series of 28 checkboxes and a 29th which checks and unchecks them all as appropriate. I have also got code so that if you manually select them all then the 29th checkbox becomes checked. My problem is getting the checkbox to uncheck if you manually uncheck one of the other 28 boxes.

Here is my code and I will put a little explanation afterwards.

NOTE - The 29th checkbox is called checkbox1.

Expand|Select|Wrap|Line Numbers
  1. Private Sub CheckBoxChecker(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged, _
  2.     CheckBox3.CheckedChanged, CheckBox4.CheckedChanged, CheckBox5.CheckedChanged, CheckBox6.CheckedChanged, _
  3.     CheckBox7.CheckedChanged, CheckBox8.CheckedChanged, CheckBox9.CheckedChanged, CheckBox10.CheckedChanged, _
  4.     CheckBox11.CheckedChanged, CheckBox12.CheckedChanged, CheckBox13.CheckedChanged, CheckBox14.CheckedChanged, _
  5.     CheckBox15.CheckedChanged, CheckBox16.CheckedChanged, CheckBox17.CheckedChanged, CheckBox18.CheckedChanged, _
  6.     CheckBox19.CheckedChanged, CheckBox20.CheckedChanged, CheckBox21.CheckedChanged, CheckBox22.CheckedChanged, _
  7.     CheckBox23.CheckedChanged, CheckBox24.CheckedChanged, CheckBox25.CheckedChanged, CheckBox26.CheckedChanged, _
  8.     CheckBox27.CheckedChanged, CheckBox28.CheckedChanged, CheckBox29.CheckedChanged
  9.  
  10.         If CheckBox2.Checked And CheckBox3.Checked And CheckBox4.Checked And CheckBox5.Checked And CheckBox6.Checked _
  11.               And CheckBox7.Checked And CheckBox8.Checked And CheckBox9.Checked And CheckBox10.Checked And CheckBox11.Checked _
  12.               And CheckBox12.Checked And CheckBox13.Checked And CheckBox14.Checked And CheckBox15.Checked And CheckBox16.Checked _
  13.               And CheckBox17.Checked And CheckBox18.Checked And CheckBox19.Checked And CheckBox20.Checked And CheckBox21.Checked _
  14.               And CheckBox22.Checked And CheckBox23.Checked And CheckBox24.Checked And CheckBox25.Checked And CheckBox26.Checked _
  15.               And CheckBox27.Checked And CheckBox28.Checked And CheckBox29.Checked = True Then CheckBox1.Checked = True
  16.     End Sub
  17.  
  18.  
  19.  
  20.  
  21.     Private Sub checkboxall(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
  22.         If CheckBox1.Checked = True Then CheckBox2.Checked = True Else CheckBox2.Checked = False
  23.         If CheckBox1.Checked = True Then CheckBox3.Checked = True Else CheckBox3.Checked = False
  24.         If CheckBox1.Checked = True Then CheckBox4.Checked = True Else CheckBox4.Checked = False
  25.         If CheckBox1.Checked = True Then CheckBox5.Checked = True Else CheckBox5.Checked = False
  26.         If CheckBox1.Checked = True Then CheckBox6.Checked = True Else CheckBox6.Checked = False
  27.         If CheckBox1.Checked = True Then CheckBox7.Checked = True Else CheckBox7.Checked = False
  28.         If CheckBox1.Checked = True Then CheckBox8.Checked = True Else CheckBox8.Checked = False
  29.         If CheckBox1.Checked = True Then CheckBox9.Checked = True Else CheckBox9.Checked = False
  30.         If CheckBox1.Checked = True Then CheckBox10.Checked = True Else CheckBox10.Checked = False
  31.         If CheckBox1.Checked = True Then CheckBox11.Checked = True Else CheckBox11.Checked = False
  32.         If CheckBox1.Checked = True Then CheckBox12.Checked = True Else CheckBox12.Checked = False
  33.         If CheckBox1.Checked = True Then CheckBox13.Checked = True Else CheckBox13.Checked = False
  34.         If CheckBox1.Checked = True Then CheckBox14.Checked = True Else CheckBox14.Checked = False
  35.         If CheckBox1.Checked = True Then CheckBox15.Checked = True Else CheckBox15.Checked = False
  36.         If CheckBox1.Checked = True Then CheckBox16.Checked = True Else CheckBox16.Checked = False
  37.         If CheckBox1.Checked = True Then CheckBox17.Checked = True Else CheckBox17.Checked = False
  38.         If CheckBox1.Checked = True Then CheckBox18.Checked = True Else CheckBox18.Checked = False
  39.         If CheckBox1.Checked = True Then CheckBox19.Checked = True Else CheckBox19.Checked = False
  40.         If CheckBox1.Checked = True Then CheckBox20.Checked = True Else CheckBox20.Checked = False
  41.         If CheckBox1.Checked = True Then CheckBox21.Checked = True Else CheckBox21.Checked = False
  42.         If CheckBox1.Checked = True Then CheckBox22.Checked = True Else CheckBox22.Checked = False
  43.         If CheckBox1.Checked = True Then CheckBox23.Checked = True Else CheckBox23.Checked = False
  44.         If CheckBox1.Checked = True Then CheckBox24.Checked = True Else CheckBox24.Checked = False
  45.         If CheckBox1.Checked = True Then CheckBox25.Checked = True Else CheckBox25.Checked = False
  46.         If CheckBox1.Checked = True Then CheckBox26.Checked = True Else CheckBox26.Checked = False
  47.         If CheckBox1.Checked = True Then CheckBox27.Checked = True Else CheckBox27.Checked = False
  48.         If CheckBox1.Checked = True Then CheckBox28.Checked = True Else CheckBox28.Checked = False
  49.         If CheckBox1.Checked = True Then CheckBox29.Checked = True Else CheckBox29.Checked = False
  50.     End Sub
  51.  
If CheckBox1 is checked then it checks the rest. If CheckBox1 is unchecked it unchecks the rest. If there is a change in CheckBox2-29 it checks to see what the rest are like and if they are all checked it checks CheckBox1 but putting an "else checkbox1.checked = false" there does not work. The problem with that is it messes up the functioning of CheckBox1 since when CheckBox1 changes CheckBox2 it raises the event CheckBox2.CheckedChanged which then checks against all the other values to see if they are equal and since they aren't yet it reverts CheckBox1 back to unchecked!

So any suggestions on how can I get the check all check box to uncheck when not all items are checked in Visual Basic 2005?
Jan 22 '08 #1
3 2798
The way you have your code written is causing the problem you are going to have to handle each checkbox seperately. like so
Expand|Select|Wrap|Line Numbers
  1. ' this part of the code checks to see if all others are checked and checks 
  2. ' unchecks box 1 as needed (Note leave out the current checkbox your working on)
  3. Private Sub CheckBoxChecker(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
  4.  If CheckBox3.Checked And CheckBox4.Checked And CheckBox5.Checked And CheckBox6.Checked _
  5.               And CheckBox7.Checked And CheckBox8.Checked And CheckBox9.Checked And CheckBox10.Checked And CheckBox11.Checked _
  6.               And CheckBox12.Checked And CheckBox13.Checked And CheckBox14.Checked And CheckBox15.Checked And CheckBox16.Checked _
  7.               And CheckBox17.Checked And CheckBox18.Checked And CheckBox19.Checked And CheckBox20.Checked And CheckBox21.Checked _
  8.               And CheckBox22.Checked And CheckBox23.Checked And CheckBox24.Checked And CheckBox25.Checked And CheckBox26.Checked _
  9.               And CheckBox27.Checked And CheckBox28.Checked And CheckBox29.Checked = True Then CheckBox1.Checked = True
  10. ' when you uncheck this box checkbox1 will also be unchecked 
  11. If CheckBox2.Checked = False Then
  12.             CheckBox1.Checked = False
  13. end sub
  14.  
  15.  
Your second piece of code for checking and unchecking all boxes looks fine.

Sorry to make your code longer but there is no other way.

Good luck,
James
Jan 24 '08 #2
Hey thanks for the reply although I think that code will still raise the same problem as the orignal.

When the all-checkbox is checked it will first check checkbox2 which will then go and see if the rest are checked and since they won't be yet it will result in the all-checkbox becoming unchecked again.

I'll go give it a try though and cross my fingers.

EDIT - Na it's not working but it's cool I'm going to change it to two buttons instead a check all and uncheck all one, that will work better.
Jan 24 '08 #3
I Believe tha is the best way using 2 boxes one to check all and 1 to uncheck all. you can still do the check on the other boxes to see if all are checked.


Happy coding
James
Jan 25 '08 #4

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

Similar topics

7
by: Mike Lopez | last post by:
Hello. I need to set a checkbox to the "checked" state and prevent the user from unchecking it. I tried using "disabled", but then the value is not passed on the Post to an ASP page. Anyone...
1
by: Phil Galey | last post by:
In VB.NET, is there a way to make it so the user can select items in a CheckedListBox, but is NOT able to check them? Even if I set Locked = True, the user is still able to both select and check...
2
by: Chelimar | last post by:
Hi, I need to tell a checkbox list that if two of the items have been checked, to uncheck themselves. I need help! Thanks :) ~Chelimar
1
by: Ramakrishnan Nagarajan | last post by:
Hi, I have two checkboxes in each row of a grid. One for Modify and another one for View. If I click Modify the View should get automatically checked and should be disabled. Earlier I did this in...
0
by: megan_c | last post by:
Hi, I have several check boxes on a form which are bound to a database record. I'm having an issue with one of them. After loading and binding the controls, i disable and enable this one(I'll...
2
by: Geovanni Cesar | last post by:
I have a table with 12 checkboxes. I have the following function which when I check the last checkbox in the table, the first 10 checkboxes in the table are unchecked. - function...
5
by: kid | last post by:
Hi, I have 5 checkbox elements, i.e: ( 1 ) a ( 2 ) b ( 3 ) c ( 4 ) d ( Check/Uncheck all )
3
by: Silgd1 | last post by:
Hey All... I have visual web jsf page, developed in netbeans 6.0, and it has a layout panel which contains three(3) checkboxes of the woodstock component variety. If a user checks one of the...
1
Death Slaught
by: Death Slaught | last post by:
I play a game that when your backpack fills with items (the limit is 45) you must choose items to discard by unchecking their box. This is very annoying and time consuming so I was wondering if it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.