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

x
?
Solved

VB.net CheckedListBox Code not picking up all checked items

Posted on 2015-02-02
3
Medium Priority
?
243 Views
Last Modified: 2015-02-02
Hi
I am using the following code to gather all the items in a CheckedListBox into a comma delimted string.
Nothing happens when I check the first box and then it seems to not include the latest box that I have
checked showing all except the last one

    Private Sub CheckedListBox1_ItemCheck(sender As Object, e As System.Windows.Forms.ItemCheckEventArgs) Handles CheckedListBox1.ItemCheck
        Try
            Dim oCheckedListBox As CheckedListBox = Me.CheckedListBox1
            Dim Label_Table As Label = Me.lblTable1
            Dim Label_Column As Label = Me.lblColumn1
            Dim oRTB As RichTextBox = Me.RichTextBox1
            Dim S1 As String = ""


            If blnReloadFilter = True Then Exit Sub
            Dim blnIsNumeric As Boolean = modDataTypes.Is_SQL_Numeric(Label_Table.Text, Label_Column.Text)
            '-----------------------------------------------------------------------

            For Each item In oCheckedListBox.CheckedItems
                If S1 = "" Then
                    If blnIsNumeric = True Then
                        S1 = item.ToString()
                    Else
                        S1 = "'" & SQLConvert(item.ToString()) & "'"
                    End If
                Else
                    If blnIsNumeric = True Then
                        S1 = S1 & "," & item.ToString()
                    Else
                        S1 = S1 & "," & "'" & SQLConvert(item.ToString()) & "'"
                    End If
                End If
                oRTB.Text = Label_Table.Text & " IN(" & S1 & ")"
            Next
            '---------------------------------------------------------------------------

        Catch ex As Exception
            MsgBox(ex.Message & " 8m1")
        End Try
    End Sub
0
Comment
Question by:Murray Brown
3 Comments
 
LVL 25

Expert Comment

by:SStory
ID: 40583924
My first thought would be to put a debug.print as the first line in the for and output raw of everything that it shows checked to be sure if they are checked or not. If they are then the problem could be in your SQLConvert or something else.
0
 
LVL 48

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 2000 total points
ID: 40584840
The checked state of an item isn't updated until the ItemCheck event has finished doing it's thing, so your code won't find the last checked item. You would probably be better using the MouseUp event instead.
0
 

Author Closing Comment

by:Murray Brown
ID: 40585477
Thanks Wayne! Worked like a charm
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month8 days, 5 hours left to enroll

824 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