[2005] Group Box and Radion Buttons
I have radio buttons grouped in a group box
Question1: Can I give each radio button a default value:
Example radio1 value = 1 ,radio2 value =2
If this is possible , How do I get which radio button is selected and what is it's value without using If statement.
Example : Messagebox.show ---> groupBox Selected radio button Value !
Re: [2005] Group Box and Radion Buttons
You can do this with the RadioButton's Tag Property
You can then loop through the controls in the Groupbox to see which one is checked
Code:
Dim selectedValue As Integer
For Each ctl As Control In Me.GroupBox1.Controls
If TypeOf (ctl) Is RadioButton Then
If DirectCast(ctl, RadioButton).Checked Then
selectedValue = ctl.Tag
Exit For
End If
End If
Next
Re: [2005] Group Box and Radion Buttons
Another way to do it would be to have a routine that handles the check changed event of the radio buttons. Put the value of each radio button that you want them to have in their Tag property and then just have something like this:
vb Code:
'Declare variables
Dim RadioValue As String
Dim RadioName As String
Private Sub GetButtonValue_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles RadioButton1.CheckedChanged, RadioButton2.CheckedChanged, RadioButton3.CheckedChanged
'Assign variables the values and use these
RadioName = DirectCast(sender, RadioButton).Name
RadioValue = DirectCast(sender, RadioButton).Tag.ToString
End Sub