Groupbox with radiobutton

A

Agnes

I create an array to store the radiobutton list. If the user click the 3rd
buttons,
I should store the value 2 into the table fields,
My method is check each radio button whether is checked or not,
if Me.rb1stbutton.checked than .. store 0
if Me.rb2..... checked then store 1
.........
if Me.rb6... checked then store 5.

Any other simple method to know which button is checked ? thanks a lot
 
M

Microsoft

Note a handler can handle more than one event, you can determine the
sender's name within the handler. The example here handler all three boxes.
Alternatively you can have a handler for each



Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles RadioButton1.CheckedChanged,
RadioButton2.CheckedChanged, RadioButton3.CheckedChanged

End Sub
 
A

Agnes

I know handler can handler many event. but my question,
How can I know which button does the user click ??
 
M

Microsoft

Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles RadioButton1.CheckedChanged,
RadioButton2.CheckedChanged, RadioButton3.CheckedChanged

Dim rb As RadioButton

rb = DirectCast(sender, RadioButton)

Select Case rb.Name

Case Me.RadioButton1.Name

'Ur Action

Case Me.RadioButton2.Name

'Ur Action

Case Me.RadioButton3.Name

'Ur Action

End Select

End Sub
 
C

Chris Dunaway

Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles RadioButton1.CheckedChanged,
RadioButton2.CheckedChanged, RadioButton3.CheckedChanged

Dim rb As RadioButton

rb = DirectCast(sender, RadioButton)

Select Case rb.Name

Rather than use a Select Case, store the associated value in the
RadioButton's Tag property Then you can use a single line in your
CheckChanged Handler:

Private Sub RadioButton_CheckedChanged(...) Handles rb1.CheckChanged,..,...
Dim x As Integer = CInt(DirectCast(sender,RadioButton).Tag)
End Sub

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 
O

One Handed Man \( OHM - Terry Burns \)

Thats an interesting and quite clever solution to her problem Chris.

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--


Chris Dunaway said:
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object,
ByVal
e As System.EventArgs) Handles RadioButton1.CheckedChanged,
RadioButton2.CheckedChanged, RadioButton3.CheckedChanged

Dim rb As RadioButton

rb = DirectCast(sender, RadioButton)

Select Case rb.Name

Rather than use a Select Case, store the associated value in the
RadioButton's Tag property Then you can use a single line in your
CheckChanged Handler:

Private Sub RadioButton_CheckedChanged(...) Handles
rb1.CheckChanged,..,...
Dim x As Integer = CInt(DirectCast(sender,RadioButton).Tag)
End Sub

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 
O

One Handed Man \( OHM - Terry Burns \)

Actually, a little variation here to avert the problems of a double fire.

Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles RadioButton1.CheckedChanged,
RadioButton2.CheckedChanged, RadioButton3.CheckedChanged

Static lastChanged As Int32

Dim rb As RadioButton = DirectCast(sender, RadioButton)

Dim tag As Int32 = CType(rb.Tag, Int32)

If lastChanged <> tag Then

Debug.WriteLine(tag.ToString)

End If

lastChanged = tag

End Sub


--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--


One Handed Man ( OHM - Terry Burns ) said:
Thats an interesting and quite clever solution to her problem Chris.

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--


Chris Dunaway said:
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object,
ByVal
e As System.EventArgs) Handles RadioButton1.CheckedChanged,
RadioButton2.CheckedChanged, RadioButton3.CheckedChanged

Dim rb As RadioButton

rb = DirectCast(sender, RadioButton)

Select Case rb.Name

Rather than use a Select Case, store the associated value in the
RadioButton's Tag property Then you can use a single line in your
CheckChanged Handler:

Private Sub RadioButton_CheckedChanged(...) Handles
rb1.CheckChanged,..,...
Dim x As Integer = CInt(DirectCast(sender,RadioButton).Tag)
End Sub

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 
A

Agnes

OH, Thanks for all your kind help
One Handed Man ( OHM - Terry Burns ) said:
Actually, a little variation here to avert the problems of a double fire.

Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles RadioButton1.CheckedChanged,
RadioButton2.CheckedChanged, RadioButton3.CheckedChanged

Static lastChanged As Int32

Dim rb As RadioButton = DirectCast(sender, RadioButton)

Dim tag As Int32 = CType(rb.Tag, Int32)

If lastChanged <> tag Then

Debug.WriteLine(tag.ToString)

End If

lastChanged = tag

End Sub


--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--


"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
Thats an interesting and quite clever solution to her problem Chris.

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--


Chris Dunaway said:
On Fri, 29 Oct 2004 12:27:39 +0100, Microsoft wrote:

Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object,
ByVal
e As System.EventArgs) Handles RadioButton1.CheckedChanged,
RadioButton2.CheckedChanged, RadioButton3.CheckedChanged

Dim rb As RadioButton

rb = DirectCast(sender, RadioButton)

Select Case rb.Name


Rather than use a Select Case, store the associated value in the
RadioButton's Tag property Then you can use a single line in your
CheckChanged Handler:

Private Sub RadioButton_CheckedChanged(...) Handles
rb1.CheckChanged,..,...
Dim x As Integer = CInt(DirectCast(sender,RadioButton).Tag)
End Sub

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 
C

Chris Dunaway

Actually, a little variation here to avert the problems of a double fire.

Perhaps a little simpler is to just check the checked property. Since
radiobutton's are mutually exclusive within the same group, only one will
be checked so you could do this to avoid a multiple fire:

Private Sub RadioButton_CheckedChanged(...) Handles rb1.CheckChanged,..,...
If DirectCast(sender,RadioButton).Checked Then
Dim x As Integer = CInt(DirectCast(sender,RadioButton).Tag)
End If
End Sub

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top