所以我最近掌握了在我的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表中,以便每行在一列中具有复选框的名称,并且在下一行中具有对应的文本框值,但我希望是一种比较常用和被接受的方法。
预先感谢您!
伟大的问题!值得投票和收藏。 – Kraxed 2013-04-11 18:26:17