组合框值取决于另一个组合框的选择

时间:2023-01-27 20:14:58

I need to selected item on 1 combobox will show dpending items from this selection in another combobox. I dont use SQL,EXEL, ACCESS or VBA in project. I added items by my self in winforms. it should look sonething like this: http://imgur.com/BYQNVzd Thanks a lot for help.

我需要在1个组合框中选择项目,将在另一个组合框中显示此选项中的待定项目。我不在项目中使用SQL,EXEL,ACCESS或VBA。我在winforms中添加了自己的项目。它看起来应该像这样:http://imgur.com/BYQNVzd非常感谢你的帮助。

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
    If ComboBox1.SelectedIndex = 0 Then
        ' Index 0 is BMW
        ComboBox2.Items.Clear()
        ComboBox2.Items.AddRange({"X5", "X6", "7-series", "5-series", "3-series"})
    ElseIf ComboBox1.SelectedIndex = 1 Then
        ' Toyota
        ComboBox2.Items.Clear()
        ComboBox2.Items.AddRange({"Teana", "Camry"})
    ElseIf ComboBox1.SelectedIndex = 2 Then
        ' kia
        ComboBox2.Items.Clear()
        ComboBox2.Items.AddRange({"Rio"})
    End If
End Sub

1 个解决方案

#1


0  

It would look like this

它看起来像这样

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
    If ComboBox1.SelectedIndex = 0 Then
        ' Index 0 is BMW
        ComboBox2.Items.Clear()
        ComboBox2.Items.AddRange({"X5", "X6", "7-series", "5-series", "3-series"})
    ElseIf ComboBox1.SelectedIndex = 1 Then
        ' Toyota

    End If
End Sub

#1


0  

It would look like this

它看起来像这样

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
    If ComboBox1.SelectedIndex = 0 Then
        ' Index 0 is BMW
        ComboBox2.Items.Clear()
        ComboBox2.Items.AddRange({"X5", "X6", "7-series", "5-series", "3-series"})
    ElseIf ComboBox1.SelectedIndex = 1 Then
        ' Toyota

    End If
End Sub