hmm i can't seem to figure out how to get the selected items from a check list box...
i have 7 items in it, need to see which ones are selected...
and how to clear the checks from the list box
Printable View
hmm i can't seem to figure out how to get the selected items from a check list box...
i have 7 items in it, need to see which ones are selected...
and how to clear the checks from the list box
First up, "selected" and "checked" are two different things when talking about a CheckedListBox, as it is actually called. "Selected" has the same meaning as in a regular ListBox and "checked" means exactly what you'd expect.
As always, your first port of call should be the documentation. Have you read the MSDN documentation for the CheckedListBox class? If not, why not? If you want to know how something works then the instructions that came with it should always be the first place you look. Being a beginner is more reason to read the documentation, not less. You may not always find what you're looking for and you may not always understand what you find but, the more often you do it, the better you will get at it.
Had you read the documentation then you'd know that a CheckedListBox has a SelectedItems property and a CheckedItems property. Both are collections so you can do with them as you would with any collection, e.g. loop through all items, get the item count an access items by index.
It is easy :
here is an example for a list box contains 3 items "hi","hello" and "Fine":
Dim x As Integer
x = ListBox1.SelectedIndex
If x = 0 Then
MsgBox("Hi")
ElseIf x = 1 Then
MsgBox("Hello")
ElseIf x = 2 Then
MsgBox("Fine")
End If