我正在尝试填充投放箱

时间:2014-08-23 11:29:59

标签: vb.net drop-down-menu

到目前为止,我已经在visual basic中填充了几个下拉框。

我可能需要全局变量,但我不知道该怎么做。我被告知使用Dim和下拉框的变量名称,但我不断收到错误,说他们已经是表单中的朋友。

*这是一项家庭作业,但我并没有要求你完成作业,只是在下拉框中询问我遇到的问题。我不希望你有多好的人为我赚取成绩!谢谢你的帮助!

Public Class Form1
    '// Mortgage Calculator Assignment 1.
    '// Can calculate payments on a given loan at a given rate for a given term.
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    End Sub
    '// Inputs rate starting at 3.25% through 6.75% at steps of 0.25% into the drop down box.
    Private Sub cbRate_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbRate.SelectedIndexChanged
        For i As Decimal = 3.25 To 6.75 Step 0.25
            cbRate.Items.Add(i & "%")
        Next
    End Sub
    '// Inputs term in years from 10 through 40 at steps of 5 year intervals into the drop down box.
    Private Sub cbTerm_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbTerm.SelectedIndexChanged
        For i As Integer = 10 To 40 Step 5
            cbTerm.Items.Add(i)
        Next
    End Sub

End Class

1 个答案:

答案 0 :(得分:2)

您不需要全局变量。

尝试只填写表单load:

中的组合框
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
   '// Inputs rate starting at 3.25% through 6.75% at steps of 0.25%
   ' into the drop down          
    For i As Decimal = 3.25 To 6.75 Step 0.25
        cbRate.Items.Add(i & "%")
    Next

    '// Inputs term in years from 10 through 40 at steps of 5 year intervals
    ' into the drop down box.
    For i As Integer = 10 To 40 Step 5
        cbTerm.Items.Add(i)
    Next
End Sub

编辑:当您将它们添加到设计器中的表单时,(可能)为您声明了组合框。