user2103670 user2103670 - 5 months ago 40
Vb.net Question

Retrieved the checked items from a CheckedListBox VB.NET Winform

I asked this question before but suggested to provide a more details. Here is the problem:


  1. I have a CheckedListBox called
    CheckedList_Facility
    . All items in this
    CheckedList_Facility
    are getting from SQL Server Datasource. All items are loaded properly using the below code

    Dim queryString As String = "SELECT Facility FROM Database.dbo.Facility "
    Dim connection As New SqlConnection(connectionString)
    Dim command As New SqlCommand(queryString, connection)
    connection.Open()
    Dim dataReader As SqlDataReader = command.ExecuteReader()
    Dim source As New BindingSource
    source.DataSource = dataReader
    CheckedList_Facility.DataSource = source
    CheckedList_Facility.ValueMember = "Facility"
    connection.Close()

  2. I would like to get a list of items that are checked. For example,

    [X] AAA

    [X] BBB

    [ ] CCC

    [ ] DDD

    [X] EEE



then the list should be "AAA", "BBB", "EEE"


  1. To test if the item is retrieved correctly, I using a button call
    bt_GetItem
    and when this button is pressed, a msgbox displays the items that are checked. With this code:

    Dim itemChecked As Object
    For Each itemChecked In CheckedList_Facility.CheckedItems
    MsgBox(itemChecked.ToString)
    Next

  2. However, I only receive this error message

    System.Data.Common.DataRecordInternal



Technically, this might not be an error but instead of receiving "AAA", I get this

System.Data.Common.DataRecordInternal

Answer

Because you bound the checkedlistbox to your datareader, the checked object internally is actually a {System.Data.Common.DataRecordInternal} and not a string or any other native object. You have to access the item property within the object to get to the string you want, like so:

 MsgBox(itemChecked.item("Facility").ToString)
Comments