|
-
May 5th, 2013, 03:44 PM
#1
Thread Starter
Lively Member
Radio Button not working
Hello, any idea how to fix this:
Code:
If RadioButton1.Checked = True Then
TextBox1.Text = "A"
ElseIf RadioButton2.Checked = True Then
TextBox1.Text = "B"
End If
So, I want, when I click (checked) radiobutton 1, in textbox1 appears letter "A", and when I click (checked) radiobutton 2, it should appears in textbox1 letter "B". The problem is with code above, that letter "A" is always in textbox1, it is not change in letter "B", when I click radiobutton2 (and radiobutton1 is unchecked). I also put both radiobuttons in GroupBox, but still not working.
Thanks for your help.
-
May 5th, 2013, 03:52 PM
#2
New Member
Re: Radio Button not working
Well, is that what you mean?
"RadioButton1" Code:
Code:
If RadioButton1.Checked = True Then
TextBox1.Text = "A"
End If
"RadioButton2" Code:
Code:
If RadioButton2.Checked = True Then
TextBox1.Text = "B"
End If
Yep?
-
May 5th, 2013, 03:57 PM
#3
Addicted Member
Re: Radio Button not working
 Originally Posted by danielkrudolf
Hello, any idea how to fix this:
Code:
If RadioButton1.Checked = True Then
TextBox1.Text = "A"
ElseIf RadioButton2.Checked = True Then
TextBox1.Text = "B"
End If
So, I want, when I click (checked) radiobutton 1, in textbox1 appears letter "A", and when I click (checked) radiobutton 2, it should appears in textbox1 letter "B". The problem is with code above, that letter "A" is always in textbox1, it is not change in letter "B", when I click radiobutton2 (and radiobutton1 is unchecked). I also put both radiobuttons in GroupBox, but still not working.
Thanks for your help. 
Under which event did you put this code? It works fine under a button click event.
-
May 5th, 2013, 03:58 PM
#4
Thread Starter
Lively Member
Re: Radio Button not working
xRedSn0w, still not wirking, it stays letter "A"
-
May 5th, 2013, 03:59 PM
#5
Thread Starter
Lively Member
Re: Radio Button not working
MetalInquisitor, event is Form_Load
-
May 5th, 2013, 04:01 PM
#6
Re: Radio Button not working
 Originally Posted by xRedSn0w
Well, is that what you mean?
"RadioButton1" Code:
Code:
If RadioButton1.Checked = True Then
TextBox1.Text = "A"
End If
"RadioButton2" Code:
Code:
If RadioButton2.Checked = True Then
TextBox1.Text = "B"
End If
Yep? 
And that's different, how exactly? It's not the code, it's when it's executed.
vb.net Code:
' NB. The handles clause at the end of this line ....
Private Sub RadioButton1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RadioButton1.CheckedChanged, RadioButton2.CheckedChanged
If RadioButton1.Checked = True Then
TextBox1.Text = "A"
ElseIf RadioButton2.Checked = True Then
TextBox1.Text = "B"
End If
End Sub
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 5th, 2013, 04:05 PM
#7
Thread Starter
Lively Member
Re: Radio Button not working
dunfiddlin, thanks a lot, it is working
-
May 5th, 2013, 04:06 PM
#8
Addicted Member
Re: Radio Button not working
Well, Form_Load fires when the form is loaded and not ever again, unless you close the form and load it again. Which means that if you click RadioButton2, your code will NOT be executed, because it's in Form_Load. You have to put that code in a RadioButton's CheckedChanged event or a Button_Click event.
Last edited by MetalInquisitor; May 5th, 2013 at 04:06 PM.
Reason: Dun beat me to it :P
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
|