尝试从所有复选框

时间:2015-05-22 21:26:12

标签: arrays checkbox vb.net-2010

我正在通过数组创建一组复选框。我可以将复选框放入我的表单中而不会出现问题。我无法从复选框中将选中的\ unchecked值转换为Excel电子表格。在" if checkbox.checked = true然后"我收到错误" MissingMemberException未处理" "公共成员'已检查'在类型'标签'没找到。"我在网上搜索过,我很难找到解决方案。

这是数组:

X = 30
Y = 75

Dim newCheck As CheckBox

For col As Integer = 1 To TskCnt

    'create a new textbox and set its properties
    newCheck = New CheckBox
    newCheck.Size = New Size(15, 14)
    newCheck.Location = New Point(X, Y)
    newCheck.Name = "Check" & col
    Me.Controls.Add(newCheck)
    Y = Y + 40
Next

这是我试图获取值的地方:

For Each CheckBox In Me.Controls
    If CheckBox.Checked = True Then
        oSheet.Range("B" & RowN).Value = "Completed"
    Else
        oSheet.Range("B" & RowN).Value = "Incomplete"
    End If
    RowN = RowN + 1
Next

1 个答案:

答案 0 :(得分:0)

我在另一个帖子中找到了我自己的解决方案:How to check if a checkbox is checked when iterating through form controls

    For Each CheckBox In Me.Controls.OfType(Of CheckBox)()
        If CheckBox.Checked = True Then
            oSheet.Range("B" & RowN).Value = "Completed"
        Else
            oSheet.Range("B" & RowN).Value = "Incomplete"
        End If
        RowN = RowN + 1
    Next