VB.net - radiobuttons

Soldato
Joined
8 Oct 2005
Posts
4,184
Location
Midlands, UK
Hi,

Just a quick one for vb.net 2005. I have 4 radiobuttons in a panel. At the load event i dont want to have any of these selected. I have tried the following in the form_load to no avail:

Code:
		rdbsds.Checked = False
		rdbBdd.Checked = False
		rdbsdsds.Checked = False
		rdbdsdsds.Checked = False

Any ideas?
 
Last edited:
suarve said:
Hi,

Just a quick one for vb.net 2005. I have 4 radiobuttons in a panel. At the load event i dont want to have any of these selected. I have tried the following in the form_load to no avail:

Code:
		rdbsds.Checked = False
		rdbBdd.Checked = False
		rdbsdsds.Checked = False
		rdbdsdsds.Checked = False

Any ideas?
The whole point of radio buttons is to always have 1 and only 1 selection selected at a time, sounds like what you want is check boxes
 
eriedor said:
The whole point of radio buttons is to always have 1 and only 1 selection selected at a time, sounds like what you want is check boxes

Yer im aware of that. But im told i need to have no of the option radio buttons selected. This is why im a tad confused.
 
Last edited:
Only way you can do this is to have each Radio Button within a seperate panel (or other container control)

Radio buttons are grouped based on their container, so if each radio button is held within it's own container, you can set them to all be True or False.

Place a container (panel, groupbox, tabpage) onto the form and drag a radio button into the container.

Gotta agree with eriedor though, it kinda goes against the grain on what a radio button is used for. If you're getting 'told' this, then I'd question the person telling you. Go on, say they're a muppet and have the principal wrong. :p
 
suarve said:
Yer im aware of that. But im told i need to have no of the option radio buttons selected. This is why im a tad confused.

You've probably been told based on VB6 behaviour, where what you have been asked would be easy (indeed default).
 
...or based on Web App behaviour (ASP.Net), where the same behaviour as VB6 applies (ie. radio button list with none of the buttons selected)
 
Telescopi said:
You've probably been told based on VB6 behaviour, where what you have been asked would be easy (indeed default).

VB6 has never been mentioned.......

Why is it that seemingly easy things like this always turn out to be the things that annoy me the most :(

EDIT: actually the most annoying part is that i have completed the main part of this excercise and am still struggling to get this to work. :(
 
Last edited:
While what everyone else has said is true about the functionality and purpose of radio buttons you should find the following will achieve exactly what you have requested


Public Class Form1
Dim mbWhileInitialising As Boolean = True

Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
mbWhileInitialising = False
End Sub

Private Sub RadioButton1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
If mbWhileInitialising Then
RadioButton1.Checked = False
End If
End Sub
End Class

Where Radio Button 1 is the first indexed radio button control placed on the form.



The reason your code in the load event is not performing is becuase it is run prior to the form layout. You don't say whether your using .net 1.0,1.1 or 2.0

if 2.0 then you could perform the same effect by simply moving the controls addition to the control container(in this case the form itself) after the performlayout method call ie. If .NET 1.0 or 1.1 you'll find similar code at the start of the form if you expand the code added by windows designer bit IIRC

Me.Name = "Form1"

Me.Text = "Form1"

Me.ResumeLayout(False)

Me.PerformLayout()

Me.Controls.Add(Me.RadioButton4)

Me.Controls.Add(Me.RadioButton3)

Me.Controls.Add(Me.RadioButton2)

Me.Controls.Add(Me.RadioButton1)

 
Last edited:
Back
Top Bottom