ABCDE ABCDE - 1 year ago 78 Question

How to get the checked items in checklistbox

I have a checklistbox and the items of it came from my database (tbl_Section) so it loads all the Section Number (Primary Key). I have 5 Section Numbers, and 3 of it will be assigned to only one teacher. I'm thinking of using While-statement but i dont know how.

To make it simpler to you, this is what i need to do:

While //index(number) is checked
//do something
Else (i know it should not be ELSE, but i dont know what keyword is to be used)
//do something
End While

Thanks a lot!

Answer Source

What you want to do is iterate through every item in your checkbox. For each item, you check if it is checked, then you act accordingly :

'We will run through each indice
For i = 0 To CheckedListBox1.Items.Count - 1
    'You can replace As Object by your object type
    'ex : Dim Item As String = CType(CheckedListBox1.Items(i), String)
    Dim Item As Object = CheckedListBox1.Items(i)

    'We ask if this item is checked or not
    If CheckedListBox1.GetItemChecked(i) Then
        'Do something if Item is checked
        'Do something else if Item is not checked
    End If
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download