Solved

auto check items in a checkboxlist from a query

Posted on 2006-11-16
7
237 Views
Last Modified: 2010-05-18
I have a checkbox list that has 75+ items in it that is filled by a query.

I then have query that brings back a list of items (lets say 20 items) how would i loop through that list and check off my checkboxlist with those 20 items
0
Comment
Question by:LeeHopkins
  • 3
  • 3
7 Comments
 
LVL 6

Expert Comment

by:riyazthad
Comment Utility
  Dim i As Integer
       ' Only selected items
        For Each i In CheckedListBox1.CheckedIndices
            For Each dr as DataRow In ds.Tables(0).Rows
              if CheckedListBox1.Items(i).ToString)= dr("Field1") then
           .....
              end if
            Next
        Next
0
 

Author Comment

by:LeeHopkins
Comment Utility


I think i kind of understand what to do.

for each i in checklistbox1.checkedindices
   for each dr as datarow in ds.tables(0).rows
        if checkedlistbox1.items(i).tostring = dr("fidld") then
                    What is the command to check that item?????????????
        end if
   next
next



0
 
LVL 10

Accepted Solution

by:
gangwisch earned 100 total points
Comment Utility

Here is your answer good luck!
Dim i As Integer
       ' Only selected items
        For Each i In CheckedListBox1.CheckedIndices
            For Each dr as DataRow In ds.Tables(0).Rows
              if CheckedListBox1.Items(i).ToString)= dr("Field1") then
           CheckedListBox1.SetItemCheckState(i,CheckState.Checked )
              end if
            Next
        Next
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 6

Expert Comment

by:riyazthad
Comment Utility
checklistbox1.checkedindices will populate selected items. So you dont want to check again whether it is checked or not.

Just compare ur datarow value with each items in checklistbox1.checkedindices.

cheers
0
 

Author Comment

by:LeeHopkins
Comment Utility
its not looping through, it just skips over the
For Each i In chkbxlstReq.CheckedIndices

            Dim x As Integer = 9

next
0
 

Author Comment

by:LeeHopkins
Comment Utility
GOT IT TO WORK

        Do While MyReader.Read
            Dim i As Integer
            i = chkbxlstReq.Items.Count
            For i = 0 To chkbxlstReq.Items.Count - 1
                If chkbxlstReq.Items(i).ToString = MyReader.Item("jobcodes") Then
                    chkbxlstReq.SetItemCheckState(i, CheckState.Checked)
                End If

            Next
        Loop
0
 
LVL 6

Expert Comment

by:riyazthad
Comment Utility
there you go.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

13 Experts available now in Live!

Get 1:1 Help Now