我如何洗牌checklistbox?

时间:2015-01-06 04:38:31

标签: vb.net

我想将文本框中的问题与checklistboxes中的答案混合起来。问题是文本框是否洗牌但是核对表框没有。

    Dim txtQ() As TextBox = {txtQ1, txtQ2, txtQ3, txtQ4, txtQ5, txtQ6, txtQ7, txtQ8, txtQ9, txtQ10}
    Dim cbA() As CheckedListBox = {cbA1, cbA2, cbA3, cbA4, cbA5, cbA6, cbA7, cbA8, cbA9, cbA10} 
     While r.Read
        If i <= 9 Then

            txtQ(i).Text = r.GetString("exam_question")
            cbA(i).Items.Clear()
            cbA(i).Items.Add("a) " & r.GetString("exam_ans_a"))
            cbA(i).Items.Add("b) " & r.GetString("exam_ans_b"))
            cbA(i).Items.Add("c) " & r.GetString("exam_ans_c"))
            cbA(i).Items.Add("d) " & r.GetString("exam_ans_d"))

            i = i + 1
        End If
    End While
    Dim n As Integer = i - 1
    Randomize()
    While i > 0
        Dim j As Integer = CInt(Int(n * Rnd()))
        i = i - 1
        Dim tmpQ As String = txtQ(i).Text
        txtQ(i).Text = txtQ(j).Text
        txtQ(j).Text = tmpQ
        Dim tmpA As CheckedListBox = cbA(i)
        cbA(i) = cbA(j)
        cbA(j) = tmpA
    End While

1 个答案:

答案 0 :(得分:1)

在TextBoxes中使用值类型属性,在CheckBoxes中使用reference-type。您应该交换那些CheckedListBox项的文本以使其正常运行。简单地将一个CheckBox项目的引用分配给另一个CheckBox项目没有任何好处。