【问题标题】:Assign values to array when a checkbox is checked VB.NET选中复选框时为数组赋值VB.NET
【发布时间】:2017-05-18 00:20:36
【问题描述】:

我有名为 checkbox_1、checkbox_2 .... 直到 checkbox_10 的复选框。我想创建一个循环来存储:如果选中了复选框,则为 1,如果未选中复选框,则为 0 - 在 locations(10) 数组中。

【问题讨论】:

  • 如果您有 10 个复选框,则您的数组需要为 locations(9)

标签: arrays vb.net checkbox basic


【解决方案1】:

这可以通过以下方式完成:

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

【讨论】:

  • 完美运行!非常感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多