473,326 Members | 2,090 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,326 software developers and data experts.

How to easily get a results from a group of radio boxes ?

I use several mutually exclusive radio boxes (with a group box).
How can I easily test which one is checked, do I need to do
a multiple if or case statement to check all of them one by one,
or is there a simpler way?
Nov 21 '05 #1
5 1258
ng
Because .Net doesn't use an array index like VB6 did, I started using a
variable the gets set whenever any of the radio buttons in a group is
clicked. Then I later just check the value of the variable.

Tom
wino wrote:
I use several mutually exclusive radio boxes (with a group box).
How can I easily test which one is checked, do I need to do
a multiple if or case statement to check all of them one by one,
or is there a simpler way?

Nov 21 '05 #2
Hello,
How are you doing?

For checking which all radio buttons are checked, you may recurse through
the controls on the form or the group box and check which all are checked.
Here is a code snippet which recurses through the controls on a groupbox and
checks if it is checked or not:

Dim gp1 As Integer
For gp1 = 0 To Me.GroupBox1.Controls.Count - 1
If TypeOf (GroupBox1.Controls.Item(gp1)) Is RadioButton And
CType(GroupBox1.Controls.Item(gp1), RadioButton).Checked = True Then
MessageBox.Show(GroupBox1.Controls.Item(gp1).Name) ' This
will show the name of the checkbox that is checked
End If
Next

I hope this helps.

Thanks
Mona
[Grapecity]

<wino> wrote in message news:uu**************@tk2msftngp13.phx.gbl...
I use several mutually exclusive radio boxes (with a group box).
How can I easily test which one is checked, do I need to do
a multiple if or case statement to check all of them one by one,
or is there a simpler way?

Nov 21 '05 #3
<wino> schrieb:
I use several mutually exclusive radio boxes (with a group box).
How can I easily test which one is checked, do I need to do
a multiple if or case statement to check all of them one by one,
or is there a simpler way?


Add a common event handler to all the radio buttons which belong to a group:

\\\
Private m_Group1SelectedRadioButton As RadioButton

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

Dim SourceControl As RadioButton = DirectCast(sender, RadioButton)
If SourceControl.Checked Then
m_Group1SelectedRadioButton = SourceControl
End If
End Sub
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4
Wino,

Put them in a groupbox.

If one changes they all change.

(You cannot have more radiobuttons checked at one time in a groupbox)

I hope this helps,

Cor
Nov 21 '05 #5
Mona has the correct solution for me, thank you Mona,
and thank you to the others as well.
Nov 21 '05 #6

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

Similar topics

1
by: Jim Quast | last post by:
I have an ASP page and a CREGReports002.vbs file coded to export data to excel. I do this by building variables in a stored procedure. The ASP page has text boxes, list boxes, and radio buttons. ...
1
by: sman | last post by:
Hi, I recently read this article on About.com on how to create required fields for a form: http://javascript.about.com/library/scripts/blformvalidate.htm Everything works great except that there...
2
by: CSDunn | last post by:
Hello, In an Access 2000 ADP subform, I have a set of two Radio buttons in a single group that are bound to a field called 'Completed'. The Completed field comes from an SQL Server 2000 table, is...
4
by: Jared | last post by:
Radio Button or Check Box and Event Procedures I need to insert either radio buttons or check boxes onto my form. I'm not sure which to use, or if there are other options. I am using the buttons...
4
by: moondaddy | last post by:
There are different times when I will have a group of checkboxes and need to force only one to be checked at a time. I would also like to do this client side and not require a postback. These...
1
by: Helen Trim | last post by:
Is there a group box property that tells you which radio button was clicked? -- Helen
6
by: loga123 | last post by:
I am using asp.net 2.0. I want to get the results of a sql query into an array at run-time. Number of records returned varies each time.....so I want to declare the dimensions of array runtime...
7
by: moksha | last post by:
Hi, I am new to javascript and i am facing a problem in coding. plz help me out. I am using javascript for dynamically creating a table row which contains text boxes and radio...
4
by: axapta | last post by:
Hi group, How can I group a couple of check boxes on my form so that only ONE can be checked an anytime? I've tried placing them onto a panel but I can still check them both. Using VB.NET...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.