sharkyenergy
sharkyenergy

Reputation: 4173

Set checkedlistbox value to checked does not work properly

I tired this both codes to set a Item checked in a checkedlistbox:

CheckedListBox2.SetItemCheckState(0, CheckState.Checked)

and

 CheckedListBox2.SetItemChecked(0, True)

both work, and set the item as checked as expected.. but if i call this code, I get a message box..

If (CheckedListBox2.SelectedItems.Count > 0) Then
   do some code...
else 
   msgbox("not good...")
end if

If i manually REMOVE the check from the checkbox and set it back then the above code does not show the msgbox.

Upvotes: 0

Views: 778

Answers (2)

NoAlias
NoAlias

Reputation: 9193

SelectedItems are different than checked items. You should change your code to reference the CheckedItems property.

If (CheckedListBox2.CheckedItems.Count > 0) Then
   'do some code...
Else 
   MsgBox("not good...")
End If

Upvotes: 2

D. Hislop
D. Hislop

Reputation: 191

You should be looking at the checked items not the selected items:

CheckedListBox2.CheckedItems.Count > 0

Upvotes: 2

Related Questions