【问题标题】:Combo Box to Another Combo Box组合框到另一个组合框
【发布时间】:2015-10-18 10:49:54
【问题描述】:

我有两个组合框 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 添加了所有项目(female,she,male,he)

我的代码的任何建议和重构将不胜感激。谢谢

【问题讨论】:

    标签: vb.net combobox


    【解决方案1】:

    在使用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
    

    【讨论】:

      猜你喜欢
      • 2016-08-23
      • 1970-01-01
      • 2014-11-22
      • 1970-01-01
      • 2015-10-19
      • 2013-04-25
      • 2017-02-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多