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? :)
Re: Radio Button not working
Quote:
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.
Re: Radio Button not working
xRedSn0w, still not wirking, it stays letter "A" :(
Re: Radio Button not working
MetalInquisitor, event is Form_Load
Re: Radio Button not working
Quote:
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
Re: Radio Button not working
dunfiddlin, thanks a lot, it is working :D
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.