Arnold Zurbito Arnold Zurbito - 4 months ago 9
Vb.net Question

How to checked Index of Checkedlistbox2 if index of Checkedlistbox1 was checked

Can anyone who can help to solve my problem?
I'm trying to checked index of Checkedlistbox2 if index of checkedlistbox1 was checked.Currently this is my code right now on vb.net.
Example: if the value of Checkedlistbox1 was

a
,
b
,
c
and for Checkedlistbox2 was
1
,
2
,
3
then if the Value of
b
at Checkedlistbox1 was checked then the value of
2
on Checkedlistbox2 was already checked.

Private Sub Checkedlistbox1_ItemCheck(sender As Object, e As ItemCheckEventArgs) Handles Checkedlistbox1.ItemCheck
If e.NewValue = CheckState.Checked Then
For Each i As Integer In Checkedlistbox1.CheckedIndices
Checkedlistbox1.SetItemChecked(i, False)
Next
'at this code I'll try to put those index of
'Checkedlistbox2 was already checked, and it
'depends upon an index checked at Checkedlistbox1
End If
End Sub

Answer

Try this!

Private Sub CheckedListBox1_ItemCheck(sender As Object, e As ItemCheckEventArgs) Handles CheckedListBox1.ItemCheck
    CheckedListBox2.SetItemChecked(e.Index, True)
End Sub