Button is disabled until a radio button is selected.

Recommended Answers

All 6 Replies

1 RadioButton, 1 Button

Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
        If RadioButton1.Checked Then Button1.Enabled = True Else Button1.Enabled = False
    End Sub

that just returns the condition for 1 radiobutton i have like 16 radiobuttons

Do I have to make another guess and assume that you only have 2 Buttons?

See if this helps.

Private Sub myCoolRadioButtons_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
                                                Handles RadioButton1.CheckedChanged, RadioButton2.CheckedChanged, RadioButton3.CheckedChanged '// etc..
        '// get # from RadioButton#.
        Dim x As String = CType(sender, RadioButton).Name.Substring(CType(sender, RadioButton).Name.IndexOf("n") + 1)
        '// enable/disable the Button that ends with the same # as your RadioButton.
        CType(Me.Controls("Button" & x), Button).Enabled = CType(sender, RadioButton).Checked
    End Sub

If that code is a little too complicated, you can use the following code sample.

Private Sub myCoolRadioButtons_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
                                                Handles RadioButton1.CheckedChanged, RadioButton2.CheckedChanged, RadioButton3.CheckedChanged '// etc..
        If RadioButton1.Checked Then Button1.Enabled = True Else Button1.Enabled = False
        If RadioButton2.Checked Then Button2.Enabled = True Else Button2.Enabled = False
        If RadioButton3.Checked Then Button3.Enabled = True Else Button3.Enabled = False
        '// etc.
    End Sub

Haha ma bad :( not in a good mood some kid reported my username and it got changed.. >.>

So yeah that works fine tho i used another method,

made checkedchanged for each radio button, and sets a text in a textbox and by default btn1 is disabled.
on textchanged to textbox btn1 is enabled :)

Haha ma bad :( not in a good mood some kid reported my username and it got changed.. >.>...

Sorry to hear such, is it ok if I move on with my life now?:D

Indeed you do that sir :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.