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

Categories

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

vb.net - Combo box functionality

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 .

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

1 Answer

0 votes
by (71.8m points)

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

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