以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  请教:遍历窗口checkbox控件问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=49105)

--  作者:bahamute
--  发布时间:2014/4/11 22:25:00
--  请教:遍历窗口checkbox控件问题
窗口有10个checkbox控件,分别命名为chb1,chb2直到chb10,想遍历一遍,并将打钩控件名称写入str

Dim str As  String
str=""
For i As Integer=1 To 10
    Dim chb As WinForm.CheckBox = e.Form.Controls("chb(i)")
    If chb(i).checked=True Then
        str=str & ","& chb(i).Text
    End If
Next

结果编译失败
编译错误:类“WinForm.CheckBox”没有默认属性,因此无法被索引。
错误代码:If chb(i).checked=True Then
请大神帮忙看看,莫非控件不能如此遍历吗?




--  作者:don
--  发布时间:2014/4/11 22:45:00
--  
Dim chb As WinForm.CheckBox 
Dim str As  String
str=""
For i As Integer=1 To 10
    chb= e.Form.Controls("chb“ & i)
    If chb.checked=True Then
        str=str & "," & chb.Text
    End If
Next

--  作者:bahamute
--  发布时间:2014/4/11 22:52:00
--  
谢谢啦,终于解决!
--  作者:lsy
--  发布时间:2014/4/12 8:28:00
--  

既然是按编号来的,名称默认就行了:

 

Dim str As  String
For i As Integer = 1 To 10
    If e.Form.Controls("CheckBox" & i).Checked Then
        str + = "," & e.Form.Controls("CheckBox" & i).Text
    End If
Next
MessageBox.Show(str)