CheckedState on dynamically created checkboxes

  • Thread starter Thread starter Mark
  • Start date Start date
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
 
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
 
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
 
Back
Top