|
-
Jun 23rd, 2004, 02:45 PM
#1
Thread Starter
Hyperactive Member
Checked Change Fires two events? (Resolved)
This codes seems to fire two events, which I guess is because there is an event fired when I leave one radio button and then another event fired when I enter a new radio button.
VB Code:
Private Sub radQ1_CheckedChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles _
radQ1.CheckedChanged, radQ2.CheckedChanged, _
radQ3.CheckedChanged, radQ4.CheckedChanged
MsgBox("You just changed the radio button.", _
MsgBoxStyle.OKOnly, "Event Fired")
FillDataGrid()
End Sub
Is there a way to do this that will fire only one event? Or is there a better way to do what I am doing, which is basically filling a datagrid based on which quarter the user chooses (4 radio buttons).
Last edited by BukHix; Jun 24th, 2004 at 08:18 AM.
-
Jun 23rd, 2004, 02:55 PM
#2
Try casting sender into a RadioButton, and only call your fill routine if the control that caused the event is selected. If is not selected, then just ignore it.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Jun 23rd, 2004, 03:04 PM
#3
Sleep mode
Continuing what crptcblade explained , this might be the code you need :
VB Code:
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged, RadioButton2.CheckedChanged
Select Case DirectCast(sender, RadioButton).Name
Case "RadioButton1"
'do this
Case "RadioButton2"
'do this
End Select
End Sub
-
Jun 23rd, 2004, 03:25 PM
#4
Thread Starter
Hyperactive Member
Thanks! Am I missing something though? I am still getting the message twice for every change.
VB Code:
Private Sub radQ1_CheckedChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles _
radQ1.CheckedChanged, radQ2.CheckedChanged, _
radQ3.CheckedChanged, radQ4.CheckedChanged
Select Case DirectCast(sender, RadioButton).Name
Case "radQ1"
MsgBox("You just changed the radio button.")
'FillDataGrid()
Case "radQ2"
MsgBox("You just changed the radio button.")
'FillDataGrid()
Case "radQ3"
MsgBox("You just changed the radio button.")
'FillDataGrid()
Case "radQ4"
MsgBox("You just changed the radio button.")
'FillDataGrid()
End Select
End Sub
-
Jun 23rd, 2004, 04:03 PM
#5
Hi.
The reason it fire's twice is because when you check a radiobutton another is automatically de-checked. so both of them will fire the event.
Your code above for checking which one is correct. You just need a IF statement before showing you messagebox.
VB Code:
Private Sub radQ1_CheckedChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles _
radQ1.CheckedChanged, radQ2.CheckedChanged, _
radQ3.CheckedChanged, radQ4.CheckedChanged
Select Case DirectCast(sender, RadioButton).Name
Case "radQ1"
IF radQ1.Checked Then MsgBox("You just changed the radio button.")
'FillDataGrid()
Case "radQ2"
IF radQ2.Checked Then MsgBox("You just changed the radio button.")
'FillDataGrid()
Case "radQ3"
IF radQ3.Checked Then MsgBox("You just changed the radio button.")
'FillDataGrid()
Case "radQ4"
IF radQ4.Checked Then MsgBox("You just changed the radio button.")
'FillDataGrid()
End Select
End Sub
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Jun 23rd, 2004, 04:11 PM
#6
Sleep mode
That's right . I've just figured it out ! . To avoid a lot of hassle , use Click event .
VB Code:
Private Sub radQ1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles radQ1.Click, radQ2.Click, radQ3.Click, radQ4.Click
Select Case DirectCast(sender, RadioButton).Name
Case "radQ1"
MsgBox("You just changed the radio button.")
'FillDataGrid()
Case "radQ2"
MsgBox("You just changed the radio button.")
'FillDataGrid()
Case "radQ3"
MsgBox("You just changed the radio button.")
'FillDataGrid()
Case "radQ4"
MsgBox("You just changed the radio button.")
'FillDataGrid()
End Select
End Sub
-
Jun 24th, 2004, 08:17 AM
#7
Thread Starter
Hyperactive Member
-
Jun 24th, 2004, 08:25 AM
#8
Sleep mode
btw , you better use MessageBox.Show method not MsgBox .
-
Jun 24th, 2004, 09:08 AM
#9
Thread Starter
Hyperactive Member
Actually I removed the message boxes completely. Their only purpose was so that I could count how many times the event was being triggered.
Thanks again.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|