Community
Showing results for 
Search instead for 
Do you mean 
Reply

Trigger an event if checkbox is clicked

Copper Contributor
Posts: 32
Country: Germany

Trigger an event if checkbox is clicked

Hi

 

i try find a posibility to trigger an event by clicking on a checkbox.  Is there a typical function/solution for a problem like that?

 

Thanks!!

Nickel Contributor
Posts: 175
Country: USA

Re: Trigger an event if checkbox is clicked

[ Edited ]

If you have the event handled, then you don't actually trigger the event, but call the event handler, so it seems like the event was triggered. Below is an example of what I mean. When the Checkbox CheckChanged event happens (or when the method is called), it'll call the method that handles the Button1.Click event as if the button was actually clicked.

 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        'DO TASKS HERE
        Dim sum As Integer = 0
        For i As Integer = 0 To 500
            sum += i
        Next
        MessageBox.Show(sum.ToString)
    End Sub

    Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
        'CALL Button1.Click Event Handler
        Button1_Click(Button1, New EventArgs)
    End Sub

 I'm just using a Button.Click event here as an example. It could be any event handler, as long as you pass the proper parameters. Hope this helps.