1 Attachment(s)
[RESOLVED] group box and radio buttons
Hi folks.
I have put some radio buttons into a group box. When I run the program and select a button, a message box pops up with a message about the current button, and then another box pops up with a message about the newly selected button. I understand that this is because CheckedChanged happens twice(for the current button and for the newly selected button).
1. What can I do so that only the change for the newly selected button is recognised? I don't care about the CheckedChanged state for the currently selected button.
2. Besides being a visual container for the radio buttons, does the group box server any other purpose, and should code for the group box be included in my code?
Thanks in advance.
Code:
Public Class Form1
Dim frequency As String
Private Sub rdoYearly_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rdoYearly.CheckedChanged
MsgBox("Yearly")
End Sub
Private Sub rdoWeekly_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rdoWeekly.CheckedChanged
MsgBox("Weekly")
End Sub
Private Sub rdoMonthly_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rdoMonthly.CheckedChanged
MsgBox("Monthly")
End Sub
Private Sub rdoDaily_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rdoDaily.CheckedChanged
MsgBox("Daily")
End Sub
End Class
Re: group box and radio buttons
Code:
If rdoYearly.Checked = True Then
MsgBox "blah blah"
End if
Re: group box and radio buttons
Hi,
Quote:
What can I do so that only the change for the newly selected button is recognised? I don't care about the CheckedChanged state for the currently selected button.
In each of your events, you would test for the state of the Checked property to see whether you need to display your message or not. i.e:-
Code:
Private Sub rdoYearly_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rdoYearly.CheckedChanged
If rdoYearly.Checked Then
MsgBox("Yearly")
End If
End Sub
Quote:
Besides being a visual container for the radio buttons, does the group box server any other purpose, and should code for the group box be included in my code?
The purpose of the GroupBox is to contain items that are related to each other, so in the case of Radio buttons, only one button can be checked at any one time. The best way to demonstrate what the GroupBox is doing is to add another GroupBox to your form, with addition radio buttons, and you will see that only one Radio button can be checked in each GroupBox and the two groups of Radio Buttons are independent of each other.
In addition to this the GroupBox, as with all controls in VB, gives you events that can be coded but in your example you do not need to worry about any events being raised by the GroupBox.
Hope that helps.
Cheers,
Ian