如何访问动态复选框

时间:2012-05-05 23:25:15

标签: vb.net-2010

嘿伙计我动态创建了一些Checkboxed,现在我想将它们的值设置为False。我的问题是我无法访问它们,因为没有说明名称。

我是这样创造的:

        For j = 0 To column - 1

        For i = 0 To row - 1
            MyCheckboxes(counter) = New CheckBox
            MyCheckboxes(counter).Visible = True
            MyCheckboxes(counter).Checked = True
            MyCheckboxes(counter).Text = ""
            MyCheckboxes(counter).Size = New Size(15, 14)
            MyCheckboxes(counter).Name = "Check" + counter.ToString
            Me.Controls.Add(MyCheckboxes(counter))
            MyCheckboxes(counter).Location = New Point(Xpos, Ypos)
            Xpos = Xpos + 20
            counter = counter + 1
        Next i
        Ypos = Ypos + 20
        Xpos = 160
    Next j

进入全局数组

   Public MyCheckboxes() As System.Windows.Forms.CheckBox

现在我想在Click事件的Button中将值设置为False:

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

    Dim i As Integer = 0


    Me.Controls("Check" & i).Checked = False 'Here it says: Checked is not a Member of 'System.Windows.Forms.Control'
    CheckBox0.Checked = False ' Here it says CheckBox0 is not declared. It may be inaccessible due to its protection level.


End Sub

我不知道我做错了什么我搜索了将近3个小时的原因。请帮我 干杯

1 个答案:

答案 0 :(得分:0)

只需通过您的阵列访问它们。

MyCheckboxes(i).Checked = False