Checkboxes

O

OpticTygre

I have 5 checkboxes on a form, and a checkbox.checkchanged event to handle
all boxes:

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles CheckBox1.CheckedChanged,
CheckBox2.CheckedChanged, CheckBox3.CheckedChanged,
CheckBox4.CheckedChanged, CheckBox5.CheckedChanged

In that sub, how can I tell which checkbox was the one that was checked?
Sender.gettype only returns the type of the object, not the specific object.
Is there another way I can tell which checkbox is which?

Thanks.
 
O

OpticTygre

Well, doing a debug.write(sender) returns
System.Windows.Forms.CheckBox, CheckState: 1

and doing a debug.write(sender.gettype.name) returns "CheckBox"

Neither returns "Checkbox1", "Checkbox2", etc... Any other thoughts?
 
C

Cor Ligthert

Hi Optic

If directcast(sender, checkbox).name = "Checkbox1" or in a select case, this
is the basic.

I hope this helps?

Cor
 
K

Ken Tucker [MVP]

Hi,

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles CheckBox1.CheckedChanged,
CheckBox2.CheckedChanged, CheckBox3.CheckedChanged

Trace.WriteLine(DirectCast(sender, CheckBox).Name)

Trace.WriteLine(DirectCast(sender, CheckBox).CheckState.ToString)

End Sub



Ken
 

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