Checkbox event handler problem

mancroft

Newcomer
Joined
May 22, 2005
Messages
4
Checkbox event handler problem

Hello

I am trying to set up an event handler to detect clicks on checkboxes IN A PANEL.

The watch window shows two strange outputs:

1. Addhandler ... expression expected
2. CheckBoxx(intCounter).CheckedChanged ... 'CheckedChanged' is not a member of 'CheckBox'

Anyway, it isn't working. Any ideas?

Thank you.

Cut-down code:

Code:
    Private Sub refreshprices_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Click

            Dim numberofprices As Integer = (CurrentMarket.prices.Length)
            Dim CheckBoxx(numberofprices) As CheckBox
            Dim Panel1 As New Panel

            Panel1.Location = New Point(10, 30)
            Panel1.Size = New Size(400, 350)

            Me.Controls.Add(Panel1)

            For intCounter As Integer = 0 To CurrentMarket.prices.Length - 1

                CheckBoxx(intCounter) = New CheckBox

                CheckBoxx(intCounter).Size = New Size(15, 15)

                CheckBoxx(intCounter).Location = New Point(20, spaceCounter)

                Panel1.Controls.Add(CheckBoxx(intCounter))

                AddHandler CheckBoxx(intCounter).CheckedChanged, AddressOf bxCheckedHandler

           Next
           
    End Sub


    Private Sub bxCheckedHandler(ByVal Sender As Object, ByVal e As System.EventArgs)
       
        MessageBox.Show(Sender.Text)
     
    End Sub
 
I changed it a bit and it works fine for me:

Code:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim num As Integer = 5
        Dim CheckBoxx(num) As CheckBox
        Dim Panel1 As New Panel

        Panel1.Location = New Point(10, 30)
        Panel1.Size = New Size(400, 350)
        Panel1.BorderStyle = BorderStyle.Fixed3D

        Me.Controls.Add(Panel1)

        For intCounter As Integer = 0 To num

            CheckBoxx(intCounter) = New CheckBox

            CheckBoxx(intCounter).Size = New Size(15, 15)

            CheckBoxx(intCounter).Location = New Point(20, intCounter * 25)

            Panel1.Controls.Add(CheckBoxx(intCounter))

            AddHandler CheckBoxx(intCounter).CheckedChanged, AddressOf CheckChanged

        Next

    End Sub

    Private Sub CheckChanged(ByVal sender As Object, ByVal e As EventArgs)


        MessageBox.Show("Check changed")

    End Sub
 
Back
Top