Solved

Add check to CheckedListBox based on query result

Posted on 2009-04-15
2
224 Views
Last Modified: 2012-05-06
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
0
Comment
Question by:crafuse
2 Comments
 
LVL 48

Accepted Solution

by:
jpaulino earned 500 total points
ID: 24149555
Why don't you do all when you add the item ?

lstCompAgainstCH.Items.Add(drReader5.Item("search_string"), drReader5.Item("is_checked"))
0
 

Author Closing Comment

by:crafuse
ID: 31570522
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
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…
Send secure, cloud-based, encrypted alerts and maintain HIPAA compliant messaging. Integrates priority & secure messaging into one application. Ensures IT, emergency respondents and healthcare professionals that their critical messages are never mis…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now