views:

961

answers:

4

I have a WinForms application (VS 2008, .NET 3.5) that has a form with two different group boxes, and inside of each group box are different sets of radio buttons. When I run the application, the first group box automatically has the first radio button in it already selected, and the second group box does not have a radio button selected by default.

I have looked through all the properties of the radio buttons and the group boxes, and cannot figure out what the difference is between the two. I would like both group boxes to have all radio buttons unselected when the form is first opened.

Also, I looked through the Designer.vb file for the form, and could not find anything unusual going on in there either.

A: 

You need to give both radio groups different group names. That may not be your issue, but it's a possible reason.

I'm curious as to why you would want radios to default to having no value at all. Radios represent boolean values - True or False - there is no other valid state.

Superstringcheese
I am hooking into the CheckedChanged events for the radio buttons, which fires additional events based on what the user is choosing. Because the first radio button is artificially being selected, some of these things are happening before they should.
BP
A: 

By saying that a checkbox is "selected", do you mean "checked"?

Sorry if this is not much help, but if you open your form in the Designer, and you look at all checkboxes' Checked property, are they really all set to False?

stakx
+1  A: 

Set all the buttons' AutoCheck property to False. You'll now have to write a Click handler for them to set their Checked property. A sample handler that takes care of two of them:

  Private Sub RadioButton_Click(ByVal sender As Object, ByVal e As EventArgs) _
      Handles RadioButton1.Click, RadioButton2.Click
    Dim button As RadioButton = DirectCast(sender, RadioButton)
    RadioButton1.Checked = button is RadioButton1
    RadioButton2.Checked = button Is RadioButton2
  End Sub
Hans Passant
+2  A: 

I've had this issue, too. I just manually set all RadioButton objects to .Checked = False in the Form_Shown event. Note that it has to be after the Form_Load event or it won't work, and the RadioButton will be set with a default.

Why? I don't know. Perhaps a bug in VB.NET.

HardCode