lundi 21 août 2017

Visual Basic- Loop to make listbox update as checkbox is checked

I'm having trouble having the listbox update as the checkbox is checked. I have a total of 8 "test_location" check boxes and I want the listbox to add items to "Steps_Queue_List" and store "1" in the "Test_Locations" array when the location is checked. Also want to clear the list when the checkbox is unchecked. This works so far but I would much prefer to learn how to make a loop for this:

Private Sub Location_CheckBox_1_CheckedChanged(sender As Object, e As EventArgs) Handles Location_CheckBox_1.CheckedChanged
    If Location_CheckBox_1.Checked Then
        Test_Locations(0) = 1
        Steps_Queue_List.Items.Add("test for location" & 1, 1)

    ElseIf Location_CheckBox_1.Checked = False Then
        Test_Locations(0) = 0
        Steps_Queue_List.Items.RemoveAt(0)
    End If
End Sub

Private Sub Location_CheckBox_2_CheckedChanged(sender As Object, e As EventArgs) Handles Location_CheckBox_2.CheckedChanged
    If Location_CheckBox_2.Checked Then
        Test_Locations(1) = 1
        Steps_Queue_List.Items.Add("test for location" & 2, 2)

    ElseIf Location_CheckBox_2.Checked = False Then
        Test_Locations(1) = 0
        Steps_Queue_List.Items.RemoveAt(0)
    End If
End Sub

Private Sub Location_CheckBox_3_CheckedChanged(sender As Object, e As EventArgs) Handles Location_CheckBox_3.CheckedChanged
    If Location_CheckBox_3.Checked Then
        Test_Locations(2) = 1
        Steps_Queue_List.Items.Add("test for location" & 3, 3)

    ElseIf Location_CheckBox_3.Checked = False Then
        Test_Locations(2) = 0
        Steps_Queue_List.Items.RemoveAt(0)
    End If
End Sub

Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire