Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

auto check items in a checkboxlist from a query

Posted on 2006-11-16
7
Medium Priority
?
253 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 400 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

886 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