-
Aug 7th, 2015, 05:17 AM
#1
Thread Starter
Member
radiobutton
hello all
Can anyone please tell me how to uncheck all the radiobuttons by default in vb window form?
I know the codes through javascript but not through vb. Please help
Thanks
-
Aug 7th, 2015, 07:54 AM
#2
Re: radiobutton
You don't need any code to uncheck them by default. You simply set the Checked property to False in the designer, which it already is by default anyway. Basically, what you're asking for is the default behavior.
Do you perhaps not actually mean by default but rather unchecking them explicitly after one may have been checked? If so then that could be done like this, assuming that all the RadioButtons have been added to the form directly:
Code:
For Each rb In Me.Controls.OfType(Of RadioButton)()
rb.Checked = False
Next
-
Aug 7th, 2015, 08:24 AM
#3
Thread Starter
Member
Re: radiobutton
Originally Posted by jmcilhinney
You don't need any code to uncheck them by default. You simply set the Checked property to False in the designer, which it already is by default anyway. Basically, what you're asking for is the default behavior.
Do you perhaps not actually mean by default but rather unchecking them explicitly after one may have been checked? If so then that could be done like this, assuming that all the RadioButtons have been added to the form directly:
Code:
For Each rb In Me.Controls.OfType(Of RadioButton)()
rb.Checked = False
Next
Thank you so much
I will try this and get back to you.
Thanks again
-
Aug 11th, 2015, 07:19 AM
#4
Thread Starter
Member
Re: radiobutton
Originally Posted by Abhi25
Thank you so much
I will try this and get back to you.
Thanks again
hi
This method doesnt work.
i still have a default checked button.
Is there any other way?
please help
Thanks
-
Aug 11th, 2015, 09:20 AM
#5
Re: radiobutton
Originally Posted by Abhi25
hi
This method doesnt work.
i still have a default checked button.
Is there any other way?
please help
Thanks
Are the RadioButtons all directly on the form? Are they in GroupBoxes or Panels? Are some on the form and some in GroupBoxes/Panels?
We know nothing of where they are or how your form is set up.
-
Aug 11th, 2015, 11:24 PM
#6
Thread Starter
Member
Re: radiobutton
Originally Posted by JuggaloBrotha
Are the RadioButtons all directly on the form? Are they in GroupBoxes or Panels? Are some on the form and some in GroupBoxes/Panels?
We know nothing of where they are or how your form is set up.
radiobuttons are inside a groupbox.
if i use this code it doesnt enter the loop:
For Each rb As RadioButton In Me.GroupBox1.Controls.OfType(Of RadioButton)()
rb.CheckedByDefault = False
Next
Where am i going wrong?
-
Aug 11th, 2015, 11:38 PM
#7
Re: radiobutton
If you mean that a RadioButton is checked when the form is first displayed then there are only two reasons that that would happen:
1. The Checked property of that RadioButton is set to True in the designer.
2. That RadioButton is the first control in the Tab order for the form.
With regards to #2, a RadioButton becomes checked when it receives focus and the first control in the Tab order gets focus when a form is first displayed. If that's your issue, the solution is generally to change the Tab order of the controls to avoid a RadioButton being first.
If that's not possible for some reason, the code I have already provided is what you would use to uncheck the RadioButton. The important thing is where you put the code. Putting it in the Load event handler is useless because that is executed before the form is displayed. You need to execute the code after the form is displayed, so you'd put it in the Shown event handler.
-
Aug 12th, 2015, 07:09 AM
#8
Thread Starter
Member
Re: radiobutton
Originally Posted by jmcilhinney
If you mean that a RadioButton is checked when the form is first displayed then there are only two reasons that that would happen:
1. The Checked property of that RadioButton is set to True in the designer.
2. That RadioButton is the first control in the Tab order for the form.
With regards to #2, a RadioButton becomes checked when it receives focus and the first control in the Tab order gets focus when a form is first displayed. If that's your issue, the solution is generally to change the Tab order of the controls to avoid a RadioButton being first.
If that's not possible for some reason, the code I have already provided is what you would use to uncheck the RadioButton. The important thing is where you put the code. Putting it in the Load event handler is useless because that is executed before the form is displayed. You need to execute the code after the form is displayed, so you'd put it in the Shown event handler.
Hi
Can you please tell me exactly how to use this code?
Shown event handler means like where?
I have still not succeeded inunchecking it.
Please help.
Thanks
-
Aug 12th, 2015, 08:23 AM
#9
Re: radiobutton
Handle the Shown event of the form and put the code there. If you don't know how to handle an event then that's probably something you should look into. It's one of the most fundamental things you can do in VB and that's why pretty much every beginners tutorial covers it. If you don't understand the fundamentals then you should take the time to work through such a tutorial. There's a link to one in my signature below.
-
Aug 13th, 2015, 05:18 AM
#10
Thread Starter
Member
Re: radiobutton
Originally Posted by jmcilhinney
Handle the Shown event of the form and put the code there. If you don't know how to handle an event then that's probably something you should look into. It's one of the most fundamental things you can do in VB and that's why pretty much every beginners tutorial covers it. If you don't understand the fundamentals then you should take the time to work through such a tutorial. There's a link to one in my signature below.
Private Sub Form1_Shown(ByVal sender As Object, ByVal e As EventArgs) _
Handles MyBase.Shown
Try
For Each rb As RadioButton In Me.GroupBox1.Controls.OfType(Of RadioButton)()
rb.CheckedByDefault = False
Next
Catch ex As Exception
End Try
End Sub
This is where I am with no output.
Where is it wrong now?
-
Aug 13th, 2015, 06:10 AM
#11
Re: radiobutton
Is there a red squiggly line under rb.CheckedByDefault = False? If not, is this a VB forms application? The line should read rb.Checked = False
-
Aug 13th, 2015, 06:43 AM
#12
Thread Starter
Member
Re: radiobutton
Originally Posted by dbasnett
Is there a red squiggly line under rb.CheckedByDefault = False? If not, is this a VB forms application? The line should read rb.Checked = False
The case is neither. It is vb.net forms application.
The compiler is not entering the FOR loop. And rb.Checked is not coming. Even if i write that its automatically taking CheckedByDefault.
Last edited by Abhi25; Aug 13th, 2015 at 07:01 AM.
-
Aug 13th, 2015, 08:04 PM
#13
Re: radiobutton
Presumably you mean that it's a Windows Forms application written in VB.NET and, if that's the case, the standard RadioButton control has no property named CheckedByDefault. If you have such a property then you are not using a standard WinForms RadioButton.
Also, I specifically stated in my first reply that that code would if the RadioButtons had been added directly to the form. The code uses the form's Controls collection so if the RadioButtons have been added to some other control, e.g. a Panel or GroupBox, then the code will be useless because you would have to use the Controls collection of that container instead.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|