我想与组合框进行比较,在这种比较下,我想删除其他组合框的值 [英] I want to compare to combobox and on that comparision i want to remove the value of other combobox

查看:69
本文介绍了我想与组合框进行比较,在这种比较下,我想删除其他组合框的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Private Sub ComboBox3_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox3.MouseEnter
    If ComboBox4.FindStringExact("G1 Bed 1") = True Then
        ComboBox3.Items.Remove("G1 Bed 1")
    Else
        ComboBox3.Items.Add("G1 Bed 1")
    End If
End Sub




如果组合框4包含"G1床1",则组合框3不应为其自身添加值.




if combobox 4 contain "G1 Bed 1" then combobox3 shuld not add value to itself

推荐答案

注意:
如果未找到与搜索到的字符串匹配的项目,则FindStringExact函数将返回-1值,否则将返回项目索引.


在开始编程之前,我们需要回答一个简单的问题: 组合框是否包含搜索到的字符串?

答案编号 combobox3 combobox4
1 FALSE FALSE
2 FALSE TRUE
3 TRUE FALSE
4 TRUE TRUE


Note:
If no items are found that match the searched string then FindStringExact function returns a -1 value, else returns an index of item.


Before we start programming, we need to answer simple question: Do the comboboxes contains searched string?

Answer no.combobox3combobox4
1FALSEFALSE
2FALSETRUE
3TRUEFALSE
4TRUETRUE


Dim iPosA as Integer = 0, iPosB as Integer = 0
iPosA = ComboBox3.FindStringExact("G1 Bed 1") 'do combobox3 contains searched string?
iPosB = ComboBox4.FindStringExact("G1 Bed 1") 'do combobox4 contains searched string?
'if combobox3 and combobox4 not contain searched string, then add it into combobox3
If iPosA = -1 And iPosB = -1 Then ComboBox3.Items.Add("G1 Bed 1")
'if combobox3 contain searched string and combobox4 contain, then remove it from combobox3
If iPosA > -1 And iPosB > -1 Then ComboBox3.Items.Remove(ComboBox3.Items(iPosA))
End If



希望对您有所帮助.



I hope it will be helpful.


这篇关于我想与组合框进行比较,在这种比较下,我想删除其他组合框的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆