473,387 Members | 1,504 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,387 software developers and data experts.

Q: Radio Buttons

Hi

I'm hoping that someone can help me with the following question about Radio
Buttons.

In MFC there is a way of attaching a variable to several radio buttons so
that it can be looked at to see which of the radio buttons is checked.
However, in VB.NET, I can't see how to do this, other than doing it manually
in the code e.g.

If RadioButton1.Checked = True
m_radio_button_checked = 1
Else If RadioButton2.Checked = True
m_radio_button_checked = 2
Else.....etc

Is there a similar technique in VB.NET that I can use?

Thanks in advance

Geoff
Nov 21 '05 #1
7 4220
Hi,

You could try something like this. I added a radio button variable to
the form. I made one common checkedchanged event handler. In the
checkedchanged procedure I assign the radio button variable to the currently
check radiobutton. When you press the button it will tell you the name of
the currently checked radio button.

Dim rb As RadioButton

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

rb = CType(sender, RadioButton)

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

MessageBox.Show(rb.Name.ToString)

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

RadioButton1.Checked = True

End Sub

Ken

-------------------------

"Geoff Jones" <no********@email.com> wrote in message
news:41***********************@news.dial.pipex.com ...
Hi

I'm hoping that someone can help me with the following question about Radio
Buttons.

In MFC there is a way of attaching a variable to several radio buttons so
that it can be looked at to see which of the radio buttons is checked.
However, in VB.NET, I can't see how to do this, other than doing it manually
in the code e.g.

If RadioButton1.Checked = True
m_radio_button_checked = 1
Else If RadioButton2.Checked = True
m_radio_button_checked = 2
Else.....etc

Is there a similar technique in VB.NET that I can use?

Thanks in advance

Geoff

Nov 21 '05 #2
"Geoff Jones" <no********@email.com> schrieb:
In MFC there is a way of attaching a variable to several radio buttons so
that it can be looked at to see which of the radio buttons is checked.
However, in VB.NET, I can't see how to do this, other than doing it
manually in the code e.g.

If RadioButton1.Checked = True
m_radio_button_checked = 1
Else If RadioButton2.Checked = True
m_radio_button_checked = 2
Else.....etc

Is there a similar technique in VB.NET that I can use?


\\\
Private m_CheckedRadioButton1 As RadioButton
..
..
..
Private Sub RadioButtons1_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_CheckedRadioButton1 = SourceControl
End If
End Sub
///

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

Nov 21 '05 #3
Thanks Ken/Herfried

Many thanks for your suggestion.

So it doesn't look as if the VC++ MFC technique is used in VB.NET. I find
this strange because, as you have indicated, to find which one of several
radio buttons is selected is awkward! Ok, in these particular cases there is
work round using a little code, but it isn't as elegant as the MFC approach
i.e. you can attach a variable to the radio buttons which stores and index
to whichever is selected.

Thanks again for your help.

Geoff

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
"Geoff Jones" <no********@email.com> schrieb:
In MFC there is a way of attaching a variable to several radio buttons so
that it can be looked at to see which of the radio buttons is checked.
However, in VB.NET, I can't see how to do this, other than doing it
manually in the code e.g.

If RadioButton1.Checked = True
m_radio_button_checked = 1
Else If RadioButton2.Checked = True
m_radio_button_checked = 2
Else.....etc

Is there a similar technique in VB.NET that I can use?


\\\
Private m_CheckedRadioButton1 As RadioButton
.
.
.
Private Sub RadioButtons1_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_CheckedRadioButton1 = SourceControl
End If
End Sub
///

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

Nov 21 '05 #4
Geoff,

The radiobutton is typical a control to place in/on a groupbox.

I assume that I make with this everything clear again.

(A simple loop in the groupbox will tell you which is checked).

I hope this helps?

Cor
Nov 21 '05 #5
Hi Cor

Ah, this had crossed my mind but I'm uncertain how to do it. If, as you
suggest, the radio buttons are in a panel, how can you determine which is
selected? Could you give some example code?

Thanks in advance

Geoff

"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Geoff,

The radiobutton is typical a control to place in/on a groupbox.

I assume that I make with this everything clear again.

(A simple loop in the groupbox will tell you which is checked).

I hope this helps?

Cor

Nov 21 '05 #6
Geoff,

I type it here so watch typos

\\\
dim checkedbutton as string
for each ctr as control in groupbox1.controls
if typeof ctr is RadioButton then
directcast(ctr,RadioButton).checked = True then
checkedbutton = ctr.name 'or the tag when you set that
exit for
end if
next
////

I hope this helps?

Cor
Nov 21 '05 #7
Thanks Cor!

A very clever idea.

Geoff

"Cor Ligthert" <no************@planet.nl> wrote in message
news:ue**************@TK2MSFTNGP09.phx.gbl...
Geoff,

I type it here so watch typos

\\\
dim checkedbutton as string
for each ctr as control in groupbox1.controls
if typeof ctr is RadioButton then
directcast(ctr,RadioButton).checked = True then
checkedbutton = ctr.name 'or the tag when you set that
exit for
end if
next
////

I hope this helps?

Cor

Nov 21 '05 #8

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

Similar topics

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: Jeff | last post by:
I'm trying to create a dynamic form that can have multiple groups of radio buttons (each group has two buttons) with the same name. Essentially, the form allows a user to enter as many names as...
4
by: Oscar Monteiro | last post by:
I Have to sets of Radio buttons like so: <input type="radio" name=p1 value=1> <input type="radio" name=p1 value=2> <input type="radio" name=p1 value=3> <br> <input type="radio" name=p2 value=1>...
6
by: Craig Keightley | last post by:
I have a page that has n number of radio groups (yes/No) how can i prevent the form being submitted if more than one radio group is not selected? By default all radio groups are unchecked ...
2
by: Rob | last post by:
Hi all, I've got multiple sets of radio button that are dynamically created in code and populated by a database query. The query returns about 20 recordsets with 3 radio buttons per recordset and...
2
by: James P. | last post by:
Help, I need to display radio buttons on a form. The data is from SQL table: each row in each table is displayed as a radio button. I have multiple SQL tables so I understand I need to put...
1
by: kenny8787 | last post by:
Hi, can anyone help here? I have the following code generated from a database, I want to have javascript calculate the costs of the selected items using radio buttons, subtotal the costs and...
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...
4
by: Blasting Cap | last post by:
I have a page that has a number of radio buttons that will be displayed to different access levels of a user who logs in to my website. For instance, if there are a dozen buttons, user1 will see...
11
by: Twayne | last post by:
Hi, Newbie to PHP here, no C or other relevant background, so pretty niave w/r to the nuances etc. but I think this is pretty basic. XP Pro, SP2+, PHP 4.4.7, XAMPP Local Apache Server...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.