Solved

VB.net CheckedListBox Code not picking up all checked items

Posted on 2015-02-02
3
238 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:murbro
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 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 500 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:murbro
ID: 40585477
Thanks Wayne! Worked like a charm
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

Title # Comments Views Activity
vb.net 1 month apart 11 38
VB.net Progress Bar - Maximum Value too large 2 24
Crystal reports login after closing form 3 34
vb.net convert long time to mm:ss 23 20
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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
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…

713 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