Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have 4 combobox in my visual basic; ComboBox1 has 3 items: Vehicle, Motorbikes, None ComboBox2 has 4 items: sportbike, casual bikes and sportcar,casual cars ComboBox3 ComboBox4 I KINDLY need a code that will let me do the following:

  1. Make combobox 2,3,4 invisible until I make a selection on combobox 1 i.e. I will choose vehicle and later progress to select sportscar meanwhile combobox 3 and 4 are invisible. In short, the next combo box only appears after making a selection on the previous one.
  2. On combobox 1, if "none" is selected the other 2,3,4 remains invincible .

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

1 Answer

On the forms Load event you need to set combo boxes 2,3 and 4 to visible=False. Then on the ComboBox1_SelectedIndexChanged event you can change combobox2 to visible=True and then do the same for each progression. The code is shown below. You will also need to decide how you want to reset previous box. In other words do you want to comboboxes 2, 3, and 4 to once again become invisible if you change from Motorbikes to none in combobox1?

Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    ComboBox2.Visible = False
    ComboBox3.Visible = False
    ComboBox4.Visible = False
End Sub

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.SelectedItem="None" then
    ComboBox2.Visible=False
    ComboBox3.Visible=False
    ComboBox4.Visible=False
Else
    ComboBox2.Visible = True
End If
End Sub
Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
    ComboBox3.Visible = True
End Sub
Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
    ComboBox4.Visible = True
End Sub
End Class

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...