父母/孩子组合框 [英] Parent/Child ComboBoxes

查看:52
本文介绍了父母/孩子组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个组合框,每个组合框都有不同的项目,但是不知何故,它是下一个组合框的特征层次结构,即:Combobox1具有车辆",摩托车"和无"作为项目.我希望能够在combobox1和Combobox2更新中选择仅与车辆相关联的项目的车辆,例如Sportscar,Sedan等.当我在combobox1中选择摩托车"时,应该会发生相同的情况,它应该使用仅与摩托车相关的项目来更新combobox2.

I have 2 combobox, each having different items but somehow it's a hierarchy of characteristics of the next combobox ie: Combobox1 has VEHICLES, MOTORBIKES and NONE as items. I want to be able to choose Vehicles in combobox1 and Combobox2 updates with items only associated with vehicles ie Sportscar, Sedan etc. The same should happen when I choose Motorcycles in combobox1, it should update combobox2 with items only related to motorcycles.

推荐答案

将此示例代码放入 ComboBox1_TextChanged事件中,以供您参考.

Put this sample code inside the ComboBox1_TextChanged Event for you to have reference.

Private Sub ComboBox1_TextChanged(sender As Object, e As EventArgs) Handles ComboBox1.TextChanged

        ComboBox2.Items.Clear()
        If ComboBox1.Text = "Vehicles" Then
            ComboBox2.Items.Add("Sportscar")
            ComboBox2.Items.Add("Sedan")
        ElseIf ComboBox1.Text = "Motorbikes" Then
            ComboBox2.Items.Add("Harley Davidson")
            ComboBox2.Items.Add("Some motorbikes")
        End If


    End Sub

您也可以在选择案例声明

Private Sub ComboBox1_TextChanged(sender As Object, e As EventArgs) Handles ComboBox1.TextChanged

        ComboBox2.Items.Clear()

        Select Case ComboBox1.Text
            Case "Vehicles"
                ComboBox2.Items.Add("Sportscar")
                ComboBox2.Items.Add("Sedan")
            Case "Motorbikes"
                ComboBox2.Items.Add("Harley Davidson")
                ComboBox2.Items.Add("Some motorbikes")
            Case Else

        End Select


    End Sub

这篇关于父母/孩子组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆