Home If Not ComboBox.SelectedItem = "String" (Or) "String2" (Or) "String3"
Reply: 2

If Not ComboBox.SelectedItem = "String" (Or) "String2" (Or) "String3"

guuh
1#
guuh Published in 2018-02-14 01:10:17Z

I wanted to make an application that when I wrote some item that is not in the combobox, it would show a messagebox saying it was to choose one of the items in the combobox.

I tried this, it probably has nothing to do with what I wanted :P

    If Not ComboBox1.SelectedItem = "Português - BR" Or "English - US" Or "Espanol - ES" Then
        MsgBox("Error")
    End If
El-Ahrairah
2#
El-Ahrairah Reply to 2018-02-14 02:58:41Z

Does this not work? If not, I'm not sure I understand your problem.

        If Not ((ComboBox1.SelectedItem.ToString = "Português - BR") _
            Or (ComboBox1.SelectedItem.ToString = "English - US") Or (ComboBox1.SelectedItem.ToString = "Espanol - ES")) Then
        MessageBox.Show("Error")
    End If
Craig
3#
Craig Reply to 2018-02-14 15:17:55Z

Notwithstanding the issues that others have identified in the If statement, the real problem is that the If is not the right way to constrain the user to only select items from the list. The right way to do this is to set the options on the Combo control so the user cannot enter their own item.

If you're using the Windows Forms control, set the DropDownStyle property to DropDownList.

If you're using the WPF control, set IsEditable to false.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.441857 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO