Search code examples
vb.netwinformschecklistbox

"conversion from type 'datarowview' to type 'string' is not valid "on Checklistbox vb.net


I have problem about my checklistbox .It have name of subject in checklistbox and I want to pop up message subject what user is checked

For Each Item As String In CheckedListBox_subject.CheckedItems
            MsgBox(Item)
Next

and i got ERROR

"conversion from type 'datarowview' to type 'string' is not valid"

at CheckedListBox_subject.CheckedItems.


Solution

  • Then use the correct type:

    For Each Item As DataRowView In CheckedListBox_subject.CheckedItems
         Dim text As String = Item(0).ToString() ' or any other column, you can also use the string overload
         MsgBox(text)
    Next