I am having difficulties populating a checkedlistbox (CLB) based on the selection(s) made in another. It should also be noted that I have a "Select All" checkbox at the top that checks/unchecks all of the items in the first CLB. Here's the code:
Private Sub chkSelectAll_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkSelectAll.CheckedChanged
For i As Integer = 0 To clb1.Items.Count - 1
clb1.SetItemChecked(i, chkSelectAll.Checked)
Next
If chkSelectAll.Checked = False Then
clb2.Items.Clear()
End If
End Sub
Private Sub clb1_ItemCheck(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles clb1.ItemCheck
Dim i As Integer = clb1.SelectedIndex
For j As Integer = 0 To al_2.Count - 1
If i = -1 Then
For k As Integer = 0 To al_2.Count - 1
If Not clb2.Items.Contains(al_2(k).sDate) Then
clb2.Items.Add(al_2(k).sDate)
Else : k += 1
End If
Next
ElseIf (e.NewValue = CheckState.Checked And al_2(j).sName = al_1(i)) Then
clb2.Items.Add(al_2(j).sDate)
ElseIf (e.NewValue = CheckState.Unchecked And al_2(j).sName = al_1(i)) Then
clbProdBkups.Items.Remove(al_2(j).sDate)
End If
Next
End Sub
The first CLB is populated with an arraylist of values on the button click event. Based on whatever is checked in the first CLB, corresponding values from an arraylist of structures should fill the second CLB. The following code partially works until the "Select All" checkbox is clicked at which point if other values have been selected before "Select All" is checked, the second CLB is filled with the correct number of corresponding values BUT only those of the most recently selected item of the first CLB instead of all of corresponding values of all of the items that were not already selected.
Any insights will be greatly appreciated.
~8th