我有2个comboxes。,..,cbocourse和cboyearandsection
如果我在cbocurse上单击BSIT,那么cboyearandsection将自动填写而不点击任何按钮,除了选择cbocourse索引
Dim BSIT() As String = {"1A", "1B", "1C", "2A", "2B", "2C", "3A", _
"3B", "3C", "4A", "4B"}
If cbocourse.SelectedIndex = "BSIS" Then
cboyear.Items.AddRange(BSIT)
答案 0 :(得分:1)
对于初学者,If cbocourse.SelectedIndex
指的是所选项目的INDEX,它将是Integer
值。您可以将组合框中的项目视为数组。
如果要与所选项目的String
值进行比较,则需要
If cbocourse.SelectedItem.toString()
答案 1 :(得分:0)
模块级别:
Dim BSIT() As String = {"1A", "1B", "1C", "2A", "2B", "2C", "3A", _
"3B", "3C", "4A", "4B"}
假设cboCourse
包含“ABC”,“DEF”,“BSIT”等字符串,则:
Private Sub cboCourse_SelectedIndexChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles cboCourse.SelectedIndex
If cboCourse.SelectedItem.ToString = "BSIS" Then
' dont want to add 2ce
cboyear.Items.Clear()
cboyear.Items.AddRange(BSIT)
End If
End Sub
注意事项:
我们不知道cboCourse
中的内容,它看起来像字符串。如果它是其他东西的对象或索引,则必须解决。在您阅读了事件和cbo Selected ...属性之后,请找出如何开始接受您获得的一些答案。