CheckedListBox - how do I get checked items in ItemCheck event

Hello All,

      Using:
    Private Function GetCheckedItems()
        Try
            Dim obj As Object
            Dim strFlds As String

            For Each obj In Me.cmbFieldList.CheckedItems()
                ' Cast the object as the correct type.
                If Len(strFlds) Then
                    strFlds &= "," & CType(obj, String)
                Else
                    strFlds = CType(obj, String)
                End If
            Next

            Return strFlds
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Err in GetCheckedItems")
        End Try
    End Function

    Private Sub cmbFieldList_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles cmbFieldList.ItemCheck

            MsgBox(GetCheckedItems)
End Sub

Part of that code I got from another post, but when called from the ItemCheck event, the item checked that caused the event to fire in the first place doesn't show up. I need to create a comma delimited string with all the checked items in the exact order they were added to the checklistbox when it was filled. 
Isn't there a 'SelectionChangeCommitted' for the CheckListBox where I can grab the checked items AFTER they are correct

Thanks,
Denvas


Answer this question

CheckedListBox - how do I get checked items in ItemCheck event

  • CheckedListBox - how do I get checked items in ItemCheck event