1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Control all checkboxes

Discussion in 'Visual Basic .NET' started by dycero, Jul 10, 2014.

  1. dycero

    dycero Newbie

    Joined:
    Aug 15, 2013
    Messages:
    22
    Likes Received:
    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?
     
  2. wolverine

    wolverine Newbie

    Joined:
    Jul 7, 2008
    Messages:
    14
    Likes Received:
    0
    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
     
  3. journeycoder

    journeycoder Newbie

    Joined:
    Aug 31, 2014
    Messages:
    27
    Likes Received:
    3
    Occupation:
    Coder: asp.net, js, php,wordpress, genesis,tools,
    Location:
    bestmicroovens.com
    Home Page:
    I still do not understand your question, can you tell me more, i will post example.
     
  4. stevie

    stevie Newbie

    Joined:
    Jul 31, 2010
    Messages:
    48
    Likes Received:
    10
    Location:
    UK
    Home Page:
    I'm not 100% sure what you mean, but I think this may help:

     
  5. manchesterfan

    manchesterfan Junior Member

    Joined:
    Jun 19, 2013
    Messages:
    115
    Likes Received:
    12
    Location:
    Manchester (duh!)
    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
     
  6. zohar

    zohar Newbie

    Joined:
    Jun 24, 2014
    Messages:
    44
    Likes Received:
    5
    It's something like..


    Code:
    For each ctrl in Me
    
     if typeof ctrl is checkbox then
     addhandler ctrl.checked, addressof myfunction
    end if
    
    next
    
     
  7. manchesterfan

    manchesterfan Junior Member

    Joined:
    Jun 19, 2013
    Messages:
    115
    Likes Received:
    12
    Location:
    Manchester (duh!)
    Same answer by using handlers given by me.
    But seems like no one is visiting this topic anymore
     
  8. zohar

    zohar Newbie

    Joined:
    Jun 24, 2014
    Messages:
    44
    Likes Received:
    5
    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..