Control all checkboxes

dycero

Newbie
Joined
Aug 15, 2013
Messages
22
Reaction score
7
Hello currently I have 6 checkboxes and each one has an on check box change associated with it that calls the same function. this function just makes sure atleast one checkbox is checked then enables a button is there a way to tie this all into one change event?
 
sure you can, go to events, checkchanged and write the function or sub you want to call for all of them. But you will have to distinguish which checkbox was checked though
 
I still do not understand your question, can you tell me more, i will post example.
 
I'm not 100% sure what you mean, but I think this may help:

Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged, CheckBox2.CheckedChanged, CheckBox3.CheckedChanged, CheckBox4.CheckedChanged, CheckBox5.CheckedChanged
'Run function here
End Sub
 
You can make this by using handles This is example with radioboxes

Code:
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AddHandler RadioButton1.Click, AddressOf rb_Click
        AddHandler RadioButton2.Click, AddressOf rb_Click
        AddHandler RadioButton3.Click, AddressOf rb_Click
        AddHandler RadioButton4.Click, AddressOf rb_Click
        AddHandler RadioButton5.Click, AddressOf rb_Click
    End Sub

    Private Sub rb_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim rb As RadioButton = DirectCast(sender, RadioButton)
        Label1.Text = rb.Text
    End Sub
End Class

Should work if you set up checkboxes
 
It's something like..


Code:
For each ctrl in Me

 if typeof ctrl is checkbox then
 addhandler ctrl.checked, addressof myfunction
end if

next
 
It's something like..


Code:
For each ctrl in Me

 if typeof ctrl is checkbox then
 addhandler ctrl.checked, addressof myfunction
end if

next

Same answer by using handlers given by me.
But seems like no one is visiting this topic anymore
 
Same answer by using handlers given by me.
But seems like no one is visiting this topic anymore

If you want one procedure to handle it all, you will have to write a event that does a checkbox[1-..].checked = (NOT checkbox1.enabled AND not checkbox2.enabled AND not checkbox3.enabled , etc, etc ] or however you want it.

Hope that helps..
 
Back
Top