[英]Combo Box to Another Combo Box
我有兩個組合框cmbo1,cmbo2。 cmbo1的項目列出了maria,john。 cmbo2有一個空項目
我想做一個if then陳述
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
但是在我選擇第二個項目“ john”之后,cmbo2卻添加了所有項目(女性,女性,男性,他)
我的代碼的任何建議和重構將不勝感激。 謝謝
您必須先清除列表中的舊選項,然后再使用Clear
功能添加新項
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.