Search code examples
arraysvb.netcheckedlistbox

how to store checked items in an array in CheckedListBox in vb.net


i'm storing all checked items in a string this works perfectly for me but i want to store all the checked items in an array with their names.

 Dim i As Integer

 Dim ListItems As String

        ListItems = "Checked Items:" & ControlChars.CrLf

        For i = 0 To (ChkListForPrint.Items.Count - 1)
            If ChkListForPrint.GetItemChecked(i) = True Then
                ListItems = ListItems & "Item " & (i + 1).ToString & " = " & ChkListForPrint.Items(i)("Name").ToString & ControlChars.CrLf
            End If
        Next

Please help!


Solution

  • This should do it.

    Dim ListItems as New List(Of String)
    For i = 0 To (ChkListForPrint.Items.Count - 1)
        If ChkListForPrint.GetItemChecked(i) = True Then
           ListItems.Add(ChkListForPrint.Items(i)("Name").ToString)
        End If
    Next