Richard Kreidl
asked on
Check to see if the majority of checkboxes are checked on a form?
I have over 30+ checkboxes on a form that I want to check to see if they're all checked and do something in which the code below works great. But I need to somehow change the code and not check for certain checkboxes.
For example checkboxes: chkNET, chkCIMS, chkLCD, chkCSI
should be excluded from the code below...
Dim AllChecked As Boolean = True
For Each c As Control In Me.Controls
If TypeOf c Is CheckBox Then
If Not CType(c, CheckBox).Checked Then
AllChecked = False
Exit For
End If
End If
Next
If AllChecked Then
'// All checkboxes are checked
MessageBox.Show("AllChecke d")
Else
MessageBox.Show("Not AllChecked")
End If
thanks
For example checkboxes: chkNET, chkCIMS, chkLCD, chkCSI
should be excluded from the code below...
Dim AllChecked As Boolean = True
For Each c As Control In Me.Controls
If TypeOf c Is CheckBox Then
If Not CType(c, CheckBox).Checked Then
AllChecked = False
Exit For
End If
End If
Next
If AllChecked Then
'// All checkboxes are checked
MessageBox.Show("AllChecke
Else
MessageBox.Show("Not AllChecked")
End If
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Where do I set the .Tag for the checkboxes I want to include?
In the IDE. Click on the CheckBox: go to Tag in the poperties window: type True if you want it included and False if you don't. Strictly, doing it that way, you ought to use string values rather than booleans, but True and False seem to work. Or you could use "a" and "b" (or whatever) and adapt the code accordingly.
Otherwise, you would need to do it programmatically.
ThisCheckBox.Tag = True
ThatCheckBox.Tag = False
'etc through all 30 ;-)
Roger
Otherwise, you would need to do it programmatically.
ThisCheckBox.Tag = True
ThatCheckBox.Tag = False
'etc through all 30 ;-)
Roger
Dim IChecked as Integer = 0
Din iCount as Integer = 0
For Each c As Control In Me.Controls
If TypeOf c Is CheckBox Then
iCount += 1
If Not CType(c, CheckBox).Checked Then
AllChecked = False
Else
iChecked += 1
End If
End If
Next
If AllChecked Then
'// All checkboxes are checked
MessageBox.Show("AllChecke
Else
MessageBox.Show("Out of " & iCount & " checkboxes " & 100.0 *cDbl(iChecked)/cDbl(iCoun
End If
AW