简体   繁体   中英

Combo Box to Another Combo Box

I have two combo box cmbo1, cmbo2. The cmbo1 has items listed maria,john. The cmbo2 has an empty items

And i want to make an if then statement like this

If Me.cmbo1.SelectedItem = "maria" Then
    Me.cmbo2.Items.Add("female")
    Me.cmbo2.Items.Add("she")
Else If me.cmbo1.selecteditem = "john" Then
    Me.cmbo2.Items.Add("male")
    Me.cmbo2.Items.Add("he")
Else
    Me.cmbo2.Items = ""
End if

But instead the cmbo2 added all the items (female,she,male,he) after I selected the second item "john"

Any advice and reconstruction of my code would be much appreciated. Thank you

You must clear the old selection from the list before adding new items using the Clear function

Me.cmbo2.Items.Clear
If Me.cmbo1.SelectedItem = "maria" Then
    Me.cmbo2.Items.Add("female")
    Me.cmbo2.Items.Add("she")
Else If Me.cmbo1.SelectedItem = "john" Then
    Me.cmbo2.Items.Add("male")
    Me.cmbo2.Items.Add("he")
End If

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM