Solved

VB.net CheckedListBox Code not picking up all checked items

Posted on 2015-02-02
3
236 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
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…

829 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