VisualBasic Make and Model ComboBox



我的目标是让这个程序能够判断选择了哪个品牌,并在此基础上提供一个模型列表。但是,当我单击组合框,执行程序并选择Make时,我在模型组合框中没有得到任何选择。有人能帮我吗?这是我的源代码:

Option Explicit On
Option Strict On
Public Class Form1
Private Sub ButtonExit_Click(sender As Object, e As EventArgs) Handles ButtonExit.Click
    Close()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    'Initialize the text property of the three Combo Boxes to a NULL string
    ComboBoxMake.Text = ""
    ComboBoxModel.Text = ""
    ComboBoxColor.Text = ""
    'Add a number of cars to the "Make" ComboBox.
    ComboBoxMake.Items.Add("Honda")
    ComboBoxMake.Items.Add("Toyota")
    ComboBoxMake.Items.Add("Ford")
    ComboBoxMake.Items.Add("Lexus")
End Sub
Private Sub ComboBoxMake_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBoxMake.SelectedIndexChanged
    Dim SelectedItem As String
    SelectedItem = CStr(ComboBoxMake.SelectedItem()) 'Return the selected item from the ComboBox
    MessageBox.Show(SelectedItem) 'Display the selected item
End Sub
Private Sub ComboBoxModel_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBoxModel.SelectedIndexChanged
    Dim SelectedItem As String
    SelectedItem = CStr(ComboBoxMake.SelectedItem()) ' Return the selected item from the ComboBox
    If SelectedItem = "Honda" Then
        ComboBoxModel.Text = "" 'Initialize the text property to a NULL string
        ComboBoxModel.Items.Clear()
        ComboBoxModel.Items.Add("Accord")
        ComboBoxModel.Items.Add("Civic")
        ComboBoxModel.Items.Add("CRV")
        ComboBoxModel.Items.Add("Pilot")
        ComboBoxModel.Items.Add("Odyssey")
    ElseIf SelectedItem = "Toyota" Then
        ComboBoxModel.Text = "" 'Initialize the text property to a NULL string
        ComboBoxModel.Items.Clear()
        ComboBoxModel.Items.Add("Camrey")
        ComboBoxModel.Items.Add("Avalon")
        ComboBoxModel.Items.Add("4Runner")
    Else
        ComboBoxModel.Items.Add("Not Available")
    End If
End Sub
End Class

在比较字符串值时尝试使用双等于。

最新更新