VB.NET Radio Button Handler Code running twice
I have a group of RadioButtons
in VB.NET. I would like to create one function that will handle all of them together. My code is below.
Private Sub employmentStatusChanged(ByVal sender As System.Object,_
ByVal e As System.EventArgs) Handles rbtnEmployed.CheckedChanged, _
rbtnUnemp.CheckedChanged, rbtnStudent.CheckedChanged, rbtnRetired.CheckedChanged
If rbtnEmployed.Checked Then
Dim employ As New Employer
employ.ShowDialog()
ElseIf rbtnStudent.Checked Then
Dim stud As New Students
stud.ShowDialog()
ElseIf rbtnRetired.Checked Then
Dim employ As New Employer
employ.ShowDialog()
End If
End Sub
This function works fine the first time I click a button. The problem comes when I click on a 开发者_高级运维different button. It fires once for the first button's changed state (from checked to unchecked) and then again for the second button (unchecked to checked).
Any ideas on how to stop this from happening? Thanks in advance!
You can't. However, sender is the radio button that was clicked. Just check the state of that. If sender.Checked is False, return from the event handler.
精彩评论