Your
CheckedListBox
and
DataGridView
are "connected" together by using some trick...
Inside the body of
DataGridView1_RowLeave
and
CheckedListBox1_SelectedIndexChanged
you call the same part of code:
...
If CheckedListBox1.GetItemCheckState(inti) = CheckState.Checked Then
(DataGridView)abcd.SetItemChecked(inti, True)
...
If you use the same part of code more then 1 times, write custom function!
So... if you move row from DataGridView (to nowhere?), you should not be surprise, because the DataGridView count of rows differ of CheckedListBox count of items. To prevent this situation, the count of items in both controls must be equal.
Read more about:
CheckedItems collection for CheckedListBox[
^]
By the way, your code:
If CheckedListBox1.GetItemCheckState(inti) = CheckState.Checked Then
abcd.SetItemChecked(inti, True)
ElseIf CheckedListBox1.GetItemCheckState(inti) = CheckState.Unchecked Then
abcd.SetItemChecked(inti, False)
End If
is not optimal! Take a look at simple trick:
Dim bChecked AS Boolean = TRUE
....
bChecked = (CheckedListBox1.GetItemCheckState(inti) = CheckState.Checked)
abcd.SetItemChecked(inti, bChecked)
Sorry for my language...