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

# 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#
 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 
 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.