CheckedState on dynamically created checkboxes

M

Mark

I have a form which during the load event creates 1 or more checkboxes.
Also, as each checkbox is added to the controls collection I also add a
handler:

AddHandler o.Click, AddressOf MedicationStop_Click

So, all of the checkboxes use the same handler

That part seems to go well. However, if a user actually checks or unchecks
one or more of the boxes, I can't seem to determine which boxes are checked
or their checked state. Can someone show me the error of my ways? Here is
my handler..

Private Sub MedicationStop_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim o As Control

'Need to show/hide a corresponding combobox depending on the checked
state
For Each o In pnlMeds.Controls
If TypeOf (o) Is CheckBox Then

'How do I determine:
'A. Which combobox was clicked
'B. What is the CheckedState
'There is no o.CheckedState property!

End If

Next
End Sub
 
A

Armin Zingler

Mark said:
I have a form which during the load event creates 1 or more
checkboxes. Also, as each checkbox is added to the controls
collection I also add a handler:

AddHandler o.Click, AddressOf MedicationStop_Click

Do you really want to handle thte Click event or maybe the CheckedChange
event?
So, all of the checkboxes use the same handler

That part seems to go well. However, if a user actually checks or
unchecks one or more of the boxes, I can't seem to determine which
boxes are checked or their checked state. Can someone show me the
error of my ways? Here is my handler..

Private Sub MedicationStop_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs)

'sender' is the sender, AKA checkbox.

dim chk = directcast(sender, checkbox)

chk.<whatever>



Armin
 
M

Mark

Perfecto! Just what I was looking for. Thanks!

Armin Zingler said:
Do you really want to handle thte Click event or maybe the CheckedChange
event?


'sender' is the sender, AKA checkbox.

dim chk = directcast(sender, checkbox)

chk.<whatever>



Armin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top