mancroft Posted June 29, 2005 Posted June 29, 2005 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 Quote
Machaira Posted June 29, 2005 Posted June 29, 2005 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 Quote Here's what I'm up to.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.