繁体   English   中英

组合框到另一个组合框

[英]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.

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