1

好的,这是相关的代码:

Public Shared compSelect(9) As ComboBox
Public Shared compPercent(9) As TextBox
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Data.LoadComponents("C:/Users/Jon/Documents/Visual Studio 2013/Projects/QuickBlend/QuickBlend/QuickBlend/Resources/databaseText.txt")
    MsgBox("finished loading")
    MainForm.compSelect = {CompSelect1, CompSelect2, CompSelect3, CompSelect4, CompSelect5, CompSelect6, CompSelect7, CompSelect8, CompSelect9, CompSelect10}
    MainForm.compPercent = {CompPercent1, CompPercent2, CompPercent3, CompPercent4, CompPercent5, CompPercent6, CompPercent7, CompPercent8, CompPercent9, CompPercent10}
    For Each box As ComboBox In MainForm.compSelect
        box.DataSource = Data.Components
        box.DisplayMember = "Name"
        For Each comp As String In Data.ComponentNames
            box.Items.Add(comp)
        Next
        MsgBox("looped")
    Next
    MsgBox("finished loop")
End Sub

如您所见,我放置了各种 MsgBoxes 来查看到底发生了什么。它从不显示“循环”消息框。谁能向我解释为什么它完全跳过了 for 循环?已经为此工作了一段时间并且厌倦了它。在此先感谢您的帮助!=)

4

2 回答 2

2

MainForm.compSelect应该是Me.compSelect因为这是实例(已填充组合框),而不仅仅是尚未填充的对象的完全限定名称。

于 2013-08-02T19:00:03.603 回答
0

您的问题是您正在为组合框设置数据源,然后尝试向其中添加项目。.NET 不喜欢这样,只会退出尝试执行此操作的 Sub,而不会发出警告(除非您添加了异常处理)。你的代码应该是...

Public Shared compSelect(9) As ComboBox
Public Shared compPercent(9) As TextBox
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Data.LoadComponents("C:/Users/Jon/Documents/Visual Studio 2013/Projects/QuickBlend/QuickBlend/QuickBlend/Resources/databaseText.txt")
MsgBox("finished loading")
MainForm.compSelect = {CompSelect1, CompSelect2, CompSelect3, CompSelect4, CompSelect5, CompSelect6, CompSelect7, CompSelect8, CompSelect9, CompSelect10}
MainForm.compPercent = {CompPercent1, CompPercent2, CompPercent3, CompPercent4, CompPercent5, CompPercent6, CompPercent7, CompPercent8, CompPercent9, CompPercent10}
For Each box As ComboBox In MainForm.compSelect
    box.DataSource = Data.Components
    box.DisplayMember = "Name"
    'take this stuff out, it is not needed
    'For Each comp As String In Data.ComponentNames
        'box.Items.Add(comp)
    'Next
    MsgBox("looped")
Next
MsgBox("finished loop")
End Sub
于 2013-08-02T19:56:49.503 回答