Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

 

   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

Posted

I changed it a bit and it works fine for me:

 

   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

Here's what I'm up to.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...