如何根据正在检查的某些复选框打印某些索引

时间:2014-02-24 04:35:44

标签: vb.net visual-studio-2010 visual-studio

下面我有一个数组,在我的设计中,我有一个包含10个选项的复选框。例如,如果选中了框1和框2,我只想打印索引0和1。我有一个按钮,打印所有的阵列成员(包括在下面),这就是我想要打印只选择的项目。我试过使用一个开关,但该文件已损坏,我迷路了。谢谢。 (语言是VB)

Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)    Handles 
btn1.Click

    Dim strDecimal(9) As String

            strDecimal(0) = FormatPercent(0.0146175)
            strDecimal(1) = FormatPercent(0.0345324585)
            strDecimal(2) = FormatPercent(0.09324543575)
            strDecimal(3) = FormatPercent(0.07346475)
            strDecimal(4) = FormatPercent(0.0772346615)
            strDecimal(5) = FormatPercent(0.42234234654)
            strDecimal(6) = FormatPercent(0.6246264664)
            strDecimal(7) = FormatPercent(0.4524642234)
            strDecimal(8) = FormatPercent(0.6876543534)
            strDecimal(9) = FormatPercent(0.6876543534)

    For num As Integer = 0 To strDecimal.Length - 1
        listArrays.Items.Add(strDecimal(num))
    Next
 End Sub

Private Sub clearList()
    listArrays.Items.Clear()
  End Sub

  Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)        Handles btn2.Click
    clearList()
  End Sub

1 个答案:

答案 0 :(得分:0)

假设您正在使用CheckedListBox并想知道哪些项目已经过检查:

Private Sub btn3_Click(sender As Object, e As EventArgs) Handles btn3.Click
    For Each itm As String In listArrays.CheckedItems
        Debug.Print(itm)
    Next
End Sub