Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

vb.net - COMBOBOX FUNCIONALITY

Screenshot of the form The code below is derived from vb form. As you can see there are 1,2,3,4 combobox with relationship hierachy ie combobox4 bares some characteristics form combobox3 and so forth. Now the issue is, when I choose lets say MOMBASA in combobox 3 and later change it to KERICHO, combobox4 updates values related to both MOMBASA and KERICHO instead of KERICHO alone.

I want to be able to make different selections in combobox3 and make combobox4 updated with relative values only or if i select another value in combobox2, combobox3 and 4 goes blank till I do a fresh selection from combox 3 all the way down

Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox3.SelectedIndexChanged
    If (ComboBox3.Text = "MOMBASA") And ComboBox2.Text = "MP" Or (ComboBox3.Text = "MOMBASA") And ComboBox2.Text = "MCA" Then

        Label4.Visible = True
        ComboBox4.Visible = True
        ComboBox4.Items.Add("CHANGAMWE")
        ComboBox4.Items.Add("JOMVU")
        ComboBox4.Items.Add("KISAUNI")
        ComboBox4.Items.Add("LIKONI")
        ComboBox4.Items.Add("MVITA")
        ComboBox4.Items.Add("NYALI")

    End If
    If (ComboBox3.Text = "KERICHO") And ComboBox2.Text = "MP" Or (ComboBox3.Text = "KERICHO") And ComboBox2.Text = "MCA" Then

        Label4.Visible = True
        ComboBox4.Visible = True
        ComboBox4.Items.Add("BELGUT")
        ComboBox4.Items.Add("BURETI")
        ComboBox4.Items.Add("KERICHO EAST")
        ComboBox4.Items.Add("KIPKELION")
        ComboBox4.Items.Add("LONDIANI")
        ComboBox4.Items.Add("SOIN SIGOWET")
    End If

End Sub

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Add a line to remove all the items before adding the items.

ComboBox4.Items.Clear() 

And also have that in your ComboBox2_SelectedIndexChanged


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...