I'm very beginner in Programming, now I'm learning with VB.NET. Here is the scenario, I have 3 checkboxes and 1 textbox. When Checkbox1 and Checkbox2 are checked then Text in the textbox becomes 1 else textbox becomes 0.
This is my code :
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged,
CheckBox2.CheckedChanged
If CheckBox1.Checked And CheckBox2.Checked Then
TextBox1.Text = 1
Else
TextBox1.Text = 0
End If
End Sub
This is working based on the scenario but when I checked all three of them, textbox doesn't change 0 and still 1. How do I solve this ? Last time I tried to change my code :
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged,
CheckBox2.CheckedChanged
If CheckBox1.Checked And CheckBox2.Checked Then
TextBox1.Text = 1
Elseif CheckBox1.Checked And CheckBox2.Checked And Checkbox3.Checked Then
TextBox1.Text = 0
Else
TextBox1.Text = 0
End If
End Sub
Or Is it possible to grouping all checkboxes in an array ? then I will count if checkboxes checked more than 2 then ... {do something}.
Aucun commentaire:
Enregistrer un commentaire