Results 1 to 8 of 8

Thread: Radio Button not working

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2013
    Posts
    120

    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.

  2. #2
    New Member xRedSn0w's Avatar
    Join Date
    May 2013
    Posts
    7

    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?

  3. #3
    Addicted Member MetalInquisitor's Avatar
    Join Date
    Sep 2012
    Posts
    143

    Re: Radio Button not working

    Quote Originally Posted by danielkrudolf View Post
    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.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Mar 2013
    Posts
    120

    Re: Radio Button not working

    xRedSn0w, still not wirking, it stays letter "A"

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2013
    Posts
    120

    Re: Radio Button not working

    MetalInquisitor, event is Form_Load

  6. #6
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Radio Button not working

    Quote Originally Posted by xRedSn0w View Post
    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:
    1. ' NB. The handles clause at the end of this line ....
    2.  
    3.     Private Sub RadioButton1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RadioButton1.CheckedChanged, RadioButton2.CheckedChanged
    4.         If RadioButton1.Checked = True Then
    5.             TextBox1.Text = "A"
    6.         ElseIf RadioButton2.Checked = True Then
    7.             TextBox1.Text = "B"
    8.         End If
    9.     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!

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Mar 2013
    Posts
    120

    Re: Radio Button not working

    dunfiddlin, thanks a lot, it is working

  8. #8
    Addicted Member MetalInquisitor's Avatar
    Join Date
    Sep 2012
    Posts
    143

    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
  •  



Click Here to Expand Forum to Full Width