Solved

Add check to CheckedListBox based on query result

Posted on 2009-04-15
2
229 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

734 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