Solved

VB.net CheckedListBox Code not picking up all checked items

Posted on 2015-02-02
3
239 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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