【发布时间】:2013-04-03 23:12:47
【问题描述】:
所以我最近掌握了在我的 Visual Basic 编程中使用类的概念,我发现它非常有用。在我当前的项目中,我有几个复选框组框(每个复选框表示一个“行为”),并且在每个组框中,总是有一个复选框具有文本框控件而不是标签(允许用户指定“其他”行为)。正是那个用户生成的标签给我带来了麻烦......
我创建了一个名为“行为”的类,它基本上执行以下操作:
- getChecked > 此方法获取每个选中的复选框并将其添加到 给定表单的 BehaviorCollection。
- behaviorCollection > 表示选中的集合 复选框。
- getOtherChecked > 的作用与“getChecked”相同,除了 “其他行为”复选框。
- otherBehaviorCollection > 表示选中的集合 “其他”复选框。
问题是对于每个选中的“其他行为”复选框,我需要存储其对应文本框的值。我想设置我的 getOtherChecked() 方法来做到这一点,这样最后我就可以做到这样......
Dim myBoxes as new Behaviors
Dim cBox as Checkbox
Dim cBoxLabel as String
myBoxes.getOtherChecked(myUserForm) 'This would get each checked "Other Behaviors" checkbox object, and also somehow add another property to it called "LinkedTextboxLabel" that would be assigned the value of the corresponding textbox.
cBox = myBoxes.otherBehaviorCollection.item(0) 'Assign a checkbox from my "Other Behaviors" collection to a variable.
cBoxLabel = cBox.LinkedTextboxLabel 'Assign the user-inputted value of the linked textbox to a variable.
所以基本上我应该/应该如何/应该向集合项或复选框添加自定义属性?
我曾考虑将控件的名称添加到临时 DataTable 或 SQL 表中,以便每一行在一列中具有复选框的名称,在下一列中具有相应的文本框值,但我希望有一种更常用和接受的方法。
提前谢谢你!
【问题讨论】:
-
好问题!值得投票和收藏。
标签: vb.net class methods properties visual-studio-2012