troubleshooting Question

Looping through checklistbox

Avatar of johnqtr
johnqtr asked on
Visual Basic.NET
1 Comment1 Solution881 ViewsLast Modified:
I have a checklistbox called "WOlist" and I also have a SQL statement that returns a value for each item in the checklistbox, or at least it's supposed to.  It will work if I only select one checkbox but if all of them are checked, no values are returned.  I think there is something wrong with my loop.  Take a look at the code and tell me where I went wrong.  Thanks!

Private Sub Print_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Print.Click
        Dim PrintDoc As New PrintDocument
        Dim PrintWO As New WorkOrder
        Dim i As Integer = 0
        Dim WO As String
        Dim exp2 As String
        Dim myReader As SqlDataReader
        Dim t1 As New TextBox
        Dim BarFont = New Font("aiagred", 9)
        'Loop through checklistbox and for each item, return expedite value and printout labels
        For Each WO In WOList.CheckedItems
            SQL = "select expedite from work_order where work_order_no = '" & WOList.SelectedIndex & "'"
            Connection.SelectQuery(SQL, myReader)
            If myReader.Read Then
                exp2 = myReader(i)
            End If
            t1.Font = BarFont
            t1.Text = WO

            PrintWO.VariableToPrint = "Date: " & DTP1.Value & vbCrLf & "W.O: " & t1.Text & vbCrLf & "Expedite: " & exp2

            'Add an event handler that will be called for each page that is generated
            AddHandler PrintDoc.PrintPage, AddressOf PrintWO.PrintWOLabel

            'Initiate the printing of the document

    End Sub
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 1 Comment.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros