Visual basic radio buttons

10.1k views Asked by At

I have a program with radio buttons that are on a second form. When one of the radio buttons become checked it is to close that form. However, the first radio button is for some reason becoming checked causing the form to close. They are all set to be false on their checked property and their index order is 1-4. I set a label as index 0. I even set them false diagrammatically in the forms onload function, but the first radio button is still becoming checked. Thank you for any help in advance.

4

There are 4 answers

2
AnthonyBlake On BEST ANSWER

You need to change them to check boxes; a radio button group always has a selection.

0
carlot0820 On

just change the tabstop property to false.

0
LarsTech On

It doesn't make much sense to have a radio button close a form, since that isn't showing a selection, but acting on one. Try changing them to Buttons.

If you have to have RadioButtons, try adding another focusable control, such as a Button, to be TabIndex=0 while the RadioButtons have TabIndexes > 0. It's just the way it works.

The other alternative is to uncheck them in the Shown event:

Private Sub Form1_Shown(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Shown
  RadioButton1.Checked = False
  RadioButton2.Checked = False
  '// etc
End Sub
0
IanB On

Or you could do what I just did, and create an extra (invisible) radio button on your form, and set that one to be checked=true. The others will then all be checked=false.

Simple.