【发布时间】:2017-05-18 00:20:36
【问题描述】:
我有名为 checkbox_1、checkbox_2 .... 直到 checkbox_10 的复选框。我想创建一个循环来存储:如果选中了复选框,则为 1,如果未选中复选框,则为 0 - 在 locations(10) 数组中。
【问题讨论】:
-
如果您有 10 个复选框,则您的数组需要为
locations(9)
标签: arrays vb.net checkbox basic
我有名为 checkbox_1、checkbox_2 .... 直到 checkbox_10 的复选框。我想创建一个循环来存储:如果选中了复选框,则为 1,如果未选中复选框,则为 0 - 在 locations(10) 数组中。
【问题讨论】:
locations(9)
标签: arrays vb.net checkbox basic
这可以通过以下方式完成:
For i As Integer = 1 To 10
Dim matches() As Control = Me.Controls.Find("checkbox_" & i, True)
If matches.Length > 0 AndAlso TypeOf matches(0) Is CheckBox Then
Dim cb As CheckBox = DirectCast(matches(0), CheckBox)
Locations(i - 1) = IIf(cb.Checked, 1, 0)
End If
Next
【讨论】: