Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB.Net - Windows Forms - Radio Buttons in Different GroupBoxes behaving like one GroupBox

Status
Not open for further replies.

jmarkus

Technical User
Oct 15, 2002
124
CA
I have a windows form with 2 group boxes. The first groupbox has 3 radio boxes which set an option when the user submits the form and the second groupbox has 2 radio boxes.

When the form loads I can see the default radio button for each groupbox is pre-selected as intended, but as soon as I click a different radio button in the first groupbox all the buttons are un-selected in the second groupbox as well.

I have the radio buttons added to each box:
Code:
me.groupBox5.Controls.Add(me.radioButton4)
me.groupBox5.Controls.Add(me.radioButton5)
me.groupBox5.Name = "groupBox5"
me.groupbox5.Location = New System.Drawing.Point(40, 406)
Me.groupBox5.Size = New System.Drawing.Size(450, 90)
me.groupbox5.Text = "Name Selection"
.
.
.
me.groupBox1.Controls.Add(me.radioButton1)
me.groupBox1.Controls.Add(me.radioButton2)
me.groupBox1.Location = New System.Drawing.Point(190, 20)
me.groupBox1.Size = New System.Drawing.Size(300, 90)
me.groupBox1.Text = "Options"

So I don't understand why they aren't behaving independently.

Any ideas?

Thanks,
Jeff
 
SOLVED

I figured it out after combing through more search results...I was adding the same controls to both the groupbox and the form so the form didn't know which controlled what.

Lesson learned: Add the radiobutton controls to groupbox and then add only the groupbox to the form.

Jeff
 
Wouldn't it be easier to set it all in Design instead of adding controls at Run time?

Have fun.

---- Andy

There is a great need for a sarcasm font.
 
Perhaps. But at this point I'm revising someone else's code and it's easier to add to what was done than change things significantly.

Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top