Не могу вывести из моего проверенного списка в vb.net

Я только изучаю vb, и у меня есть некоторые проблемы с выводом определенных проверенных элементов в моем текстовом поле. Я пробовал много способов, но все еще не могу найти правильный, может я что-то забыл?

    Private Sub submitBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles submitBtn.Click
    Dim output As String
    Dim listOfProd As String
    listOfProd = ""


    output = "Selected Region: " + destination.Text + Environment.NewLine + "Seleted Place: " +
        places.SelectedItem + Environment.NewLine + "Accomodation: " +
        accomodation.Text + Environment.NewLine + "Products Selected: " + Environment.NewLine

    For i As Integer = 0 To products.Items.Count
        If products.Items(i) Is products.CheckedItems Then
            listOfProd = listOfProd + products.Items(i)

        End If
    Next

    output = output + listOfProd

    outputHere.Text = output

1 ответ

Решение

Вместо того, чтобы просматривать циклы и определять, какие элементы списка флажков отмечены, просто используйте CheckedItems Коллекция, как это:

' Loop through only the items that are checked 
For Each itemChecked In products.CheckedItems
    ' Get the text of the selected item and append it to the output string
    listOfProd = listOfProd + itemChecked.ToString()
Next 
Другие вопросы по тегам