Solved

auto check items in a checkboxlist from a query

Posted on 2006-11-16
7
243 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 
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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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