Solved

VB.net CheckedListBox Code not picking up all checked items

Posted on 2015-02-02
3
230 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks Wayne! Worked like a charm
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

771 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now