473,383 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Radio Button Grouping in vb/VS 2005

All,

Is there an easy way to interate through a group of radio buttons (9 of 'em)
contained within a group box in VS2005. I really don't want to have to
evaluate each one...

TIA!

Tom
Mar 3 '06 #1
4 7577

"Thomas Homan" <th****@co.gila.az.us> wrote in message
news:ee**************@TK2MSFTNGP09.phx.gbl...
Is there an easy way to interate through a group of radio buttons (9 of
'em) contained within a group box in VS2005. I really don't want to have
to evaluate each one...


You can write one sub/function to handle them all. Set the .Tag value to the
Button number.

Here is a horrible example:

Private Sub RadioButtons_CheckedChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged, _
RadioButton2.CheckedChanged, RadioButton3.CheckedChanged, _
RadioButton4.CheckedChanged, RadioButton5.CheckedChanged, _
RadioButton6.CheckedChanged, RadioButton7.CheckedChanged, _
RadioButton8.CheckedChanged, RadioButton9.CheckedChanged
Debug.Print(sender.tag)
RadioButton1.BackColor = Drawing.SystemColors.Control
RadioButton2.BackColor = Drawing.SystemColors.Control
RadioButton3.BackColor = Drawing.SystemColors.Control
RadioButton4.BackColor = Drawing.SystemColors.Control
RadioButton5.BackColor = Drawing.SystemColors.Control
RadioButton6.BackColor = Drawing.SystemColors.Control
RadioButton7.BackColor = Drawing.SystemColors.Control
RadioButton8.BackColor = Drawing.SystemColors.Control
RadioButton9.BackColor = Drawing.SystemColors.Control
Select Case sender.tag
Case 1
RadioButton1.BackColor = Color.Red
Case 2
RadioButton2.BackColor = Color.Red
Case 3
RadioButton3.BackColor = Color.Red
Case 4
RadioButton4.BackColor = Color.Red
Case 5
RadioButton5.BackColor = Color.Red
Case 6
RadioButton6.BackColor = Color.Red
Case 7
RadioButton7.BackColor = Color.Red
Case 8
RadioButton8.BackColor = Color.Red
Case 9
RadioButton9.BackColor = Color.Red
End Select
End Sub
Mar 3 '06 #2
Below are a few functions I put together to identify the selected
radiobutton in a group box. The first function is a button click event
that kicked off the test. The second is the one that lookes for the
radiobutton. I hope this helps.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click

Dim ARadioButton As RadioButton
ARadioButton = GetCheckedRadioButton(Me.GroupBox1)
If ARadioButton Is Nothing Then
MessageBox.Show("Please select an option.")
Else
MessageBox.Show(ARadioButton.Text)
End If

End Sub

Protected Function GetCheckedRadioButton(ByVal Parent As Control)
As RadioButton
Dim AControl As Control
Dim ARadioButton As RadioButton

For Each AControl In Parent.Controls
If AControl.GetType() Is GetType(RadioButton) Then
ARadioButton = DirectCast(AControl, RadioButton)
If ARadioButton.Checked Then Return ARadioButton
End If
Next

Return Nothing
End Function

Mar 3 '06 #3
That works, thanks!
"Homer J Simpson" <no****@nowhere.com> wrote in message
news:T2NNf.10801$vC4.8888@clgrps12...

"Thomas Homan" <th****@co.gila.az.us> wrote in message
news:ee**************@TK2MSFTNGP09.phx.gbl...
Is there an easy way to interate through a group of radio buttons (9 of
'em) contained within a group box in VS2005. I really don't want to have
to evaluate each one...


You can write one sub/function to handle them all. Set the .Tag value to
the Button number.

Here is a horrible example:

Private Sub RadioButtons_CheckedChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged, _
RadioButton2.CheckedChanged, RadioButton3.CheckedChanged, _
RadioButton4.CheckedChanged, RadioButton5.CheckedChanged, _
RadioButton6.CheckedChanged, RadioButton7.CheckedChanged, _
RadioButton8.CheckedChanged, RadioButton9.CheckedChanged
Debug.Print(sender.tag)
RadioButton1.BackColor = Drawing.SystemColors.Control
RadioButton2.BackColor = Drawing.SystemColors.Control
RadioButton3.BackColor = Drawing.SystemColors.Control
RadioButton4.BackColor = Drawing.SystemColors.Control
RadioButton5.BackColor = Drawing.SystemColors.Control
RadioButton6.BackColor = Drawing.SystemColors.Control
RadioButton7.BackColor = Drawing.SystemColors.Control
RadioButton8.BackColor = Drawing.SystemColors.Control
RadioButton9.BackColor = Drawing.SystemColors.Control
Select Case sender.tag
Case 1
RadioButton1.BackColor = Color.Red
Case 2
RadioButton2.BackColor = Color.Red
Case 3
RadioButton3.BackColor = Color.Red
Case 4
RadioButton4.BackColor = Color.Red
Case 5
RadioButton5.BackColor = Color.Red
Case 6
RadioButton6.BackColor = Color.Red
Case 7
RadioButton7.BackColor = Color.Red
Case 8
RadioButton8.BackColor = Color.Red
Case 9
RadioButton9.BackColor = Color.Red
End Select
End Sub

Mar 3 '06 #4
Thanks virgil, that fits my needs exactly

Tom
"Virgil" <vs*******@trilliumteam.com> wrote in message
news:11*********************@v46g2000cwv.googlegro ups.com...
Below are a few functions I put together to identify the selected
radiobutton in a group box. The first function is a button click event
that kicked off the test. The second is the one that lookes for the
radiobutton. I hope this helps.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click

Dim ARadioButton As RadioButton
ARadioButton = GetCheckedRadioButton(Me.GroupBox1)
If ARadioButton Is Nothing Then
MessageBox.Show("Please select an option.")
Else
MessageBox.Show(ARadioButton.Text)
End If

End Sub

Protected Function GetCheckedRadioButton(ByVal Parent As Control)
As RadioButton
Dim AControl As Control
Dim ARadioButton As RadioButton

For Each AControl In Parent.Controls
If AControl.GetType() Is GetType(RadioButton) Then
ARadioButton = DirectCast(AControl, RadioButton)
If ARadioButton.Checked Then Return ARadioButton
End If
Next

Return Nothing
End Function

Mar 3 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: mitch-co2 | last post by:
What I am trying to do is when someone clicks on the YES radio button I want the text field called MYTEXT to equal the text field named DATE. The below code works as long as I do NOT UN-COMMENT...
8
by: wl | last post by:
Hi, I have a radiobutton group in HTML in a form: Sex: <input type="radio" name="Sex" value="male">Male <input type="radio" name="Sex" value="female">Female <input type="radio" name="Sex"...
2
by: jimi_xyz | last post by:
I am creating a search engine and here is what i have so far.. <form class="complex-form" name="searchForm" method="post" action="Directory.asp"> <TABLE border="1" cellspacing="2"...
1
by: Brian Henry | last post by:
In standard VB.NET you can group radio buttons in a pannel or frame and when you click on one in that frame or pannel the others will update relative to the selection so only the one you picked is...
3
by: Amelyan | last post by:
When we want radio button to belong to a group name we say, radio1.GroupName="GroupA". In this case, radio1 will be unselected if another radio button is selected in "GroupA". Is there a way...
6
by: Blinky | last post by:
Hi all, I have a dynamically generated page that can have 1 or more radio buttons. I am using javascript with onsubmit in the form statement to make sure a radio button is selected before...
1
by: Scott D Johnson | last post by:
I am using Visual Studio .NET 2003 (I also have VS .NET 2005 installed) I have a group of four radio buttons, and button, to set the first radio button as checked. When I run the app, and say...
2
by: dpazza | last post by:
Hi, I'm creating a quiz on using a form in VB 2005 express. I have four sets of questions and answers (labels and radio buttons) and I change between which set of questions is currently shown on...
10
by: =?Utf-8?B?UGFycm90?= | last post by:
I have 8 radio buttons on my Windows form but I can only select up to the first 4. If I click on any button beyond the 4th one and then come back into the program again the 4th button is always...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.