Solved

Add check to CheckedListBox based on query result

Posted on 2009-04-15
2
223 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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

744 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

16 Experts available now in Live!

Get 1:1 Help Now