none
How do i if combobox1.selected.item.contains(combobox2.items)

    Question

  • if combobox selected item exist in combobox2 i want do something..

    If ComboBox1.SelectedItem.Contains(ComboBox2) ????

    Sunday, March 19, 2017 3:00 AM

All replies

  • if combobox selected item exist in combobox2 i want do something..

    If ComboBox1.SelectedItem.Contains(ComboBox2) ????

    Hi

    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
    


    Regards Les, Livingston, Scotland

    Sunday, March 19, 2017 3:44 AM