Radio Button Collections Help!

  • Thread starter Thread starter Patrick
  • Start date Start date
P

Patrick

Hello - I'm working on a VB program that uses two radio button collections -
one of State, the other of Capitols. If the state is selected in
collection1, then the appropriate capitol is selected in collection2, and
vice versa.

I thought this would be easy, but it's turning into a pain - all examples
and text I can find refer to different type of collections:

I can figure out how to enumerate which button was selected from the first
collection and how to setup the collections on form load and setup the
parallel values, but how do I select the right radio button in the second
collection? All examples I have are passing text values to a box, or a
picture to a picturebox, not passing a value to a radio button collection.

Any help would be appreciated, and thanks!
 
Patrick,

Did you already set the buttons in a groupbox (or a panel) that makes
working with radiobuttons easier.

Cor
 
Hi

Here is some code, you may have a try to see if this is what you want.

Add two groupboxs and three radiobutton into each groupbox.
i.e.
Form1--- groupbox1---radio1,radio2,radio3
|
|
-- groupbox2-- radio4,radio5,radio6

Dim rbStates(2) As RadioButton
Dim rgCapitols(2) As RadioButton
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
For i As Integer = 0 To 2
rbStates(i) = GroupBox1.Controls(i)
AddHandler rbStates(i).Click, AddressOf rbStates_Click
Next
For i As Integer = 0 To 2
rgCapitols(i) = GroupBox2.Controls(i)
AddHandler rgCapitols(i).Click, AddressOf rgCapitols_Click
Next
End Sub
Private Sub rbStates_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
For i As Integer = 0 To 2
If sender Is rbStates(i) Then
rgCapitols(i).Checked = True
End If
Next
End Sub
Private Sub rgCapitols_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
For i As Integer = 0 To 2
If sender Is rgCapitols(i) Then
rbStates(i).Checked = True
End If
Next
End Sub

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top