以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]数组可以给给复选框控件赋值吗?  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=106976)

--  作者:zyl19810322
--  发布时间:2017/9/19 14:11:00
--  [求助]数组可以给给复选框控件赋值吗?
在窗口中,可以用数组给复选框赋值吗?比如这样的代码
Dim a1 As WinForm.CheckBox = e.Form.Controls("CheckBox1")
Dim a2 As WinForm.CheckBox = e.Form.Controls("CheckBox2")
Dim a3 As WinForm.CheckBox = e.Form.Controls("CheckBox3")
Dim vs() As String = {"Y","N","N"}
Dim ks() As Boolean = {a1.Checked,a2.Checked,a3.Checked}
For l As Byte = 0 To 2
    If vs(l) = "Y" Then
        ks(l) = True
    End If
Next
但是好像又行不通,用这样的方式,复选框没有任何变化,老师有其他建议吗?
已经搞定了,是Dim ks() As Boolean = {a1.Checked,a2.Checked,a3.Checked}错了
[此贴子已经被作者于2017/9/19 14:20:20编辑过]

--  作者:有点甜
--  发布时间:2017/9/19 14:27:00
--  
Dim a1 As WinForm.CheckBox = e.Form.Controls("CheckBox1")
Dim a2 As WinForm.CheckBox = e.Form.Controls("CheckBox2")
Dim a3 As WinForm.CheckBox = e.Form.Controls("CheckBox3")
Dim vs() As String = {"Y","N","N"}
Dim ks() As object = {a1,a2,a3}
For l As Byte = 0 To 2
    If vs(l) = "Y" Then
        ks(l).checked = True
    Else
        ks(l).checked = False
    End If
Next