【问题标题】:can't output from my checkedlistbox in vb.net无法从我在 vb.net 中的选中列表框中输出
【发布时间】:2016-02-16 00:52:05
【问题描述】:

我刚刚学习 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

【问题讨论】:

    标签: vb.net checkbox tchecklistbox


    【解决方案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 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-04
      • 1970-01-01
      • 2016-04-25
      • 1970-01-01
      • 2022-11-01
      • 1970-01-01
      • 2020-11-15
      相关资源
      最近更新 更多