ComboBox Question in Visual Basic?

I am trying to create a combobox dropdown list of countries. When user click on a country, it should add to the listbox. I manage to do it. But I want to enhance some form of checking. If the country is already added in the listbox, the user should not be able to select the same country again. These are my codes,... show more I am trying to create a combobox dropdown list of countries. When user click on a country, it should add to the listbox. I manage to do it. But I want to enhance some form of checking. If the country is already added in the listbox, the user should not be able to select the same country again. These are my codes, but it won't work. I don't know what's wrong. Can someone please help? Thanks!

For Each country As String In lstCountry.Items
If country Is cbxCountries.SelectedItem Then
MsgBox("County already selected.", MsgBoxStyle.Information, )
Else
lstCountry.Items.Add(cbxCountries.Select...
End If
Next
Update: My friend added another Boolean variable. For Each country In lstCountry.Items If cbxCountries.SelectedItem = country Then MsgBox ("Country already selected", ) selected = True End If Next If Not selected Then ... show more My friend added another Boolean variable.

For Each country In lstCountry.Items
If cbxCountries.SelectedItem = country Then
MsgBox ("Country already selected", )
selected = True
End If
Next

If Not selected Then
lstCountry.Items.Add(cbxCountries.Items(...
End If

But I still don't understand why my IF-Else won't work?! Why need another variable? Why must separate into 2 If clauses?
Please... I need to understand this. Please help!
2 answers 2