Solved

Add check to CheckedListBox based on query result

Posted on 2009-04-15
2
230 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

Industry Leaders: 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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

617 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