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

Determining which radiobutton within a Groupbox

P: n/a
Is there an easy, flexible way to determine which radiobutton is checked
within a groupbox without having to code for each button explicitly? It
seems there would be some kind of index you could use but I can't find
anything in the VS help or on MSDN online.

Something like:

(pseudocode)

If grpBox1.item(3).checked then

or

Select Case grpBox1.Item
Case 1....
Also, if there is an index, and you have more than one row/column of
buttons, how are they numbered?
I also want to make sure they have checked a button within the group
(meaning it starts out with no radiobuttons checked; i.e. I don't want there
to be a "default"). Is there a way to make sure a radiobutton within the
group is checked without having to ask about each radiobutton explicitly?

--
Thanks,
Ricky W. Hunt
freendeed
Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"Ricky W. Hunt" <rh*****@hotmail.com> wrote in message
news:gpALc.157185$Oq2.11358@attbi_s52...
Is there an easy, flexible way to determine which radiobutton is checked
within a groupbox without having to code for each button explicitly? It
seems there would be some kind of index you could use but I can't find
anything in the VS help or on MSDN online.


No, there is nothing like this. Many people put code behind the buttons to
set a private variable, but there is simply nothing built-in to do this for
you.
Nov 20 '05 #2

P: n/a
"Jeff Johnson [MVP: VB]" <i.***@enough.spam> wrote in message
news:uG**************@TK2MSFTNGP09.phx.gbl...

"Ricky W. Hunt" <rh*****@hotmail.com> wrote in message
news:gpALc.157185$Oq2.11358@attbi_s52...
Is there an easy, flexible way to determine which radiobutton is checked
within a groupbox without having to code for each button explicitly? It
seems there would be some kind of index you could use but I can't find
anything in the VS help or on MSDN online.
No, there is nothing like this. Many people put code behind the buttons to
set a private variable, but there is simply nothing built-in to do this

for you.


Thanks.
Nov 20 '05 #3

P: n/a
Ricky,

Yes you can.

Beneath is an sample of my with checkboxes, it is alreaydy again old so
maybe there can be someting optimezed.

You can drag this on a new project and start to see it working. You can as
well create the technique by setting the radiobuttons using the designer
which needs a little different technique in creating the radiobutton array,
however try this first.

I hope this helps?

Cor

Private myCheckbox(10) As CheckBox
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
' makes 10 checkboxes
' you need for this to drag a button on a form
Dim start As Integer = 4
Dim top As Integer = 18
Dim i As Integer
For i = 1 To 10
myCheckbox(i) = New CheckBox
myCheckbox(i).TextAlign = ContentAlignment.MiddleCenter
myCheckbox(i).Width = 40
myCheckbox(i).Height = 20
myCheckbox(i).Location = New System.Drawing.Point(start, top)
myCheckbox(i).Text = i.ToString
myCheckbox(i).Cursor = Cursors.Hand
Me.Controls.Add(myCheckbox(i))
AddHandler myCheckbox(i).Click, AddressOf myCheckBox_Click
start = start + 40
If i = 5 Then
top = top + 20
start = 4
End If
Next
End Sub
Private Sub myCheckBox_Click _
(ByVal sender As Object, ByVal e As System.EventArgs)
Dim chk As CheckBox = DirectCast(sender, CheckBox)
MessageBox.Show(chk.Text)
End Sub
Private Sub Button1_Click _
(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles Button1.Click
Dim ctr As Control
Dim a As New System.Text.StringBuilder
a.Remove(0, a.Length)
Dim i As Integer
For i = 1 To 10
If myCheckbox(i).Checked Then
a.Append(i.ToString)
End If
Next
MessageBox.Show(a.ToString)
End Sub

I hope this helps a little bit?

Cor
Nov 20 '05 #4

P: n/a
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:OM**************@TK2MSFTNGP12.phx.gbl...
Ricky,

Yes you can.

Beneath is an sample of my with checkboxes, it is alreaydy again old so
maybe there can be someting optimezed.

You can drag this on a new project and start to see it working. You can as
well create the technique by setting the radiobuttons using the designer
which needs a little different technique in creating the radiobutton array, however try this first.

I hope this helps?


Got it. Thanks.
Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.