我有两个组合框cmbo1,cmbo2。cmbo1的项目列出了maria,john。cmbo2中有一个空项目
我想做一个if if语句,像这样
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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句