By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,310 Members | 1,951 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,310 IT Pros & Developers. It's quick & easy.

groupbox and radiobutton relationship - which radiobutton is check

P: n/a
Hello,

GroupBox1 contains 3 radiobuttons. Is there a builtin way - a Container
property - in the groupbox control to determine which radiobutton is checked
- if any? I did not see anything like GroupBox1.Value, but in pseudocode I
am thinking something like

Console.WriteLine(GroupBox1.Value.ToString)

I tried

Console.WriteLine(GroupBox1.Container.Components.C ount.ToString)

but got an Object Not Set error.

Am I limited to looping through an array of radiobuttons to see which one is
checked?

Dim arrRads() as radioButton
arrRads = New RadioButton(){rad1, rad2, rad3}
....
For Each rad In arrRads
If rad.Checked.Equals(True) Then Console.WriteLine(rad.Name " = True")
Next

What is the correct way - most efficient way to determine - return the
checked radiobutton in the GroupBox? Say you have GroupBox1 and GroupBox2,
they each contain 3 radiobuttons. Are the 3 radiobuttons in GroupBox1 part
of GroupBox1 and the 3 in GroupBox2 part of GroupBox2 or is each radiobutton
an independent entity to be treated independently of the Groupbox it is
contained in?

Thanks,
Rich
Jan 29 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Rich" <Ri**@discussions.microsoft.comschrieb:
GroupBox1 contains 3 radiobuttons. Is there a builtin way - a Container
property - in the groupbox control to determine which radiobutton is
checked
- if any? I did not see anything like GroupBox1.Value, but in pseudocode
I
am thinking something like
No, there is no such property, but you can easily maintain it on your own.
To do so, 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://dotnet.mvps.org/dotnet/faqs/>

Jan 30 '07 #2

P: n/a
Thank you. That was just the tip that I needed. I will use Event handlers
for each groupbox. I was actually thinking of using array.IndexOf for a 2
dimensional array where I would have an array of arrays of radiobuttons
within each groupbox. But array.IndexOf only works with 1 dimensional
arrays. So your suggestion solves my problem.

Thank,
Rich

"Herfried K. Wagner [MVP]" wrote:
"Rich" <Ri**@discussions.microsoft.comschrieb:
GroupBox1 contains 3 radiobuttons. Is there a builtin way - a Container
property - in the groupbox control to determine which radiobutton is
checked
- if any? I did not see anything like GroupBox1.Value, but in pseudocode
I
am thinking something like

No, there is no such property, but you can easily maintain it on your own.
To do so, 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://dotnet.mvps.org/dotnet/faqs/>

Jan 30 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.