Solved

auto check items in a checkboxlist from a query

Posted on 2006-11-16
7
238 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
ID: 17960676
  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
ID: 17960746


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
ID: 17960820

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
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.

 
LVL 6

Expert Comment

by:riyazthad
ID: 17960821
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
ID: 17960908
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
ID: 17961087
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
ID: 17962057
there you go.
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

Suggested Solutions

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…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

20 Experts available now in Live!

Get 1:1 Help Now