Link to home
Start Free TrialLog in
Avatar of crafuse
crafuseFlag for Canada

asked on

Add check to CheckedListBox based on query result

Experts -

I'm sure this is very simple, but --> How the heck do I check an item as it's being added to the checkedlistbox via sqlreader?

Code:

Do While drReader5.Read()
            lstCompAgainstCH.Items.Add(drReader5.Item("search_string"))

            If drReader5.Item("is_checked") = True Then
                lstCompAgainstCH.SetItemChecked(Me.lstCompAgainstCH.SelectedIndex, True)  --> this is the line that's killing me -> what is the index of the current value just added?
            End If

            lstAgainstItemsCount = lstAgainstItemsCount + 1
        Loop
ASKER CERTIFIED SOLUTION
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of crafuse

ASKER

Sweet. I actually solved it just a moment after posting the question, but I prefer yer solution! I did this:

If drReader5.Item("is_checked") = True Then
                lstCompAgainstCH.SetItemChecked(lstAgainstItemsCount, True)
            End If