Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

group box radio button event

Status
Not open for further replies.

vttech

Technical User
Jan 28, 2006
297
0
0
US
I want to pass a string to a variable based on if the user checks a radio button that is contained in a group box

what event for the group box will trigger based on if one of the radio button objects is checked?


Code:
Private Sub gbxToTemp_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gbxToTemp.Enter
        Dim ToTemp As String
        If radFahrenheit.Checked Then
            ToTemp = "Fahrenheit"
        ElseIf radCelsius.Checked Then
            ToTemp = "Celsius"
        ElseIf radReamur.Checked Then
            ToTemp = "Reamur"
        ElseIf radRankine.Checked Then
            ToTemp = "Rankine"
        ElseIf radKelvin.Checked Then
            ToTemp = "Kelvin"
        End If
End Sub

Newbie in search of knowledge
 
You could use something like this:

Code:
Private Sub gbxToTemp_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radFahrenheit.Checked, radCelsius.Checked, radReamur.Checked, radRankine.Checked, radKelvin.Checked

  dim ToTemp as string
  ToTemp = ctype(Sender,checkbox.gettype()).caption

End Sub
(Not tested!)

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
I would do this:

1. Write to each radio button's TAG the above strings
2. Group the .Click() events like: (write the rest)

*** NOTE: the 'ToTemp' variable seems LOCAL.. and it is available only in that sub !

Code:
Private Sub gbxToTempRadioButtons(ByVal sender As System.Object, ByVal e As System.EventArgs) _
  Handles RadioFar.click, RadioCel.Click, RadioRea.click

    Dim ToTemp As String = Ctype(sender, RadioButton).Tag

End Sub


// Not tested
 
Hey Rick
We wrote almost the same .. and both not tested ...LOL
 
Yup, I know mine won't compile as is now that I re-read the thread. For some reason I was thinking they were check boxes. And I couldn't remember the name of the event to handle.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
' Stole Rick and Tip's code ;)

Public Class Form1
Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radFahrenheit.Click, _
radCelsius.Click, _
radReamur.Click, _
radRankine.Click, _
radKelvin.Click
Dim ToTemp As String = CType(sender, RadioButton).Text
MsgBox(ToTemp)
End Sub
End Class
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top