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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to have all radio buttons unchecked at form load? 1

Status
Not open for further replies.

mkrausnick

Programmer
Apr 2, 2002
766
US
I'm learning VB 2008. I have 3 radio buttons on a VB form, all with a Checked value of False. When I run the form, the first radio button is checked. I want all the buttons to initially be unchecked, and the user will check one of them.

How can I do that?

Thanks for your help.

Mike Krausnick
Dublin, California
 
If the Checked property of all RadioButtons is set to False in the designer, then, unless you have some code somewhere that changes this they should all still be unchecked when the form first loads.

However ...
Code:
	Private Sub UncheckRadioButtons(ByVal ctrl As Control)

		For Each c As Control In ctrl.Controls
			If TypeOf c Is RadioButton Then
				CType(c, RadioButton).Checked = False
			Else
				If c.HasChildren Then UncheckRadioButtons(c)
			End If
		Next

	End Sub

which could be called from the FormLoad event or anywhere that is convenient by:

Code:
        UncheckRadioButtons(Me)
 
My personal feeling is that you shouldn't design your program to have all radio buttons in a group unchecked. That being said, when I placed radio buttons on the form as you said, none of them were checked initially (I'm using VS2005). Are you sure you're not placing them in a GroupBox?
 
Thanks for the prompt reply. Playing around, I changed AutoCheck to False, ran the form, discovered that's NOT what I wanted, changed it back to True, ran the form again, and now magically all the radio buttons come up unchecked.

Beats the heck out of me, but I will definitely squirrel away your function for the next time this happens!



Mike Krausnick
Dublin, California
 
Sorry, Dave, I didn't see your response. I didn't place the buttons in any container other than the form, and there's no code anywhere in the form yet. It didn't make sense to me that it should have come up that way. But it's ok now, so maybe it was just a bad dream.

Mike Krausnick
Dublin, California
 

I agree with Dave - when you have a group of radio buttons, one of them SHOULD be checked by default.

When you have all of them unchecked and you select one, how can go get back to original setting with none of them checked?


Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top