Solved

auto check items in a checkboxlist from a query

Posted on 2006-11-16
7
246 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
[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
  • 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
Independent Software Vendors: 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!

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

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: 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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

738 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