how to check the checkbox easily ?

  • Thread starter Thread starter Agnes
  • Start date Start date
A

Agnes

I got 30 checkboxes in one Page, the user need to click at least one of it
and then , the user can go to next step.
Any simple method to check the checkboxes ?
I don't want to use the following approach.
If Me.chk1.checked = false .and........................Me.chk30.checked =
false
message.box("Warning, one Check boxes must be choose"...

Thanks a lot
 
Agnes said:
I got 30 checkboxes in one Page, the user need to click at least one of it
and then , the user can go to next step.
Any simple method to check the checkboxes ?
I don't want to use the following approach.
If Me.chk1.checked = false .and........................Me.chk30.checked =
false
message.box("Warning, one Check boxes must be choose"...

Assuming all your checkboxes were in a groupbox try the following.

Dim objControl As Object
Dim CheckOK As Boolean = False

For Each objControl In GroupBox1.Controls

If TypeOf objControl Is CheckBox AndAlso DirectCast(objControl,
CheckBox).Checked Then CheckOK = True

Next



Steve
 
Agnes,

Roughly typed

In your form load event
\\\
For Each ctl As Control in me.Controls
if typeoff of ctl Is CheckBox Then
AddHandler ctl.CheckedChanged, AddressOf CheckBoxChanged
end if
Next
///
\\\
Private CheckBoxChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs)
if directcast(sender, control).name = "checkbox1" then
'do something because of the change
end if
End sub
///

I hope this helps,

Cor


Cor
 
You can have a variable that holds the number of boxes checked and then
in the CheckedChanged event, if the CheckBox is checked, increment the
variable otherwise decrement. If the variable is > 0 then at least one
checkbox is checked.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top