本文介绍了如果combobox1.selected.item.contains(combobox2.items)该怎么办的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果选择了组合框项存在于combobox2中,我想做某事.

如果ComboBox1.SelectedItem.包含(ComboBox2)????

推荐答案

如果ComboBox1.SelectedItem.包含(ComboBox2)????

也许这段代码会有所帮助.

Maybe this code will help.

Option Strict On
Option Explicit On
Option Infer Off
Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ComboBox1.Items.AddRange({"One", "Two", "Three", "Four", "Five"})
        ComboBox2.Items.AddRange({"OnE", "Two", "three", "Fourty", "Five"})
    End Sub
    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        Dim cb As ComboBox = DirectCast(sender, ComboBox)

        ' NOTE: comparisons are case sensitive
        If ComboBox2.Items.Contains(cb.SelectedItem) Then
            MessageBox.Show("'" & cb.SelectedItem.ToString & "' - is in CB2")
            ' this is where I think you want your code to
            ' be as there is a match
        Else
            MessageBox.Show("'" & cb.SelectedItem.ToString & "' - is NOT in CB2")
        End If
    End Sub
End Class


这篇关于如果combobox1.selected.item.contains(combobox2.items)该怎么办的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 05:10