You are looping with "For i as Integer =1 to ...." but you don't use
it. You are checking SelectedItem (and you would want to check
SelectedItem.ToString rather than the object itself) where you should
check each item in the ComboBox whether it is selected or not - use
ComboBox1.items(i).ToString. Now maybe you are checking only the
selectedItem to see if it's text matches what you are inputing, but
what if the dup is somewhere else??
So fix both of those things and see which is needed...-
SelectedItem.ToString
and
ComboBox1.items(i).ToString
to see what fits with your logic....
On Fri, 24 Sep 2004 00:21:03 GMT, Supra <su*****@rogers.com> wrote:
does ne 1 know how to prevent duplicated in combobox? i convert from
vb6 to vb.net. but in vb6 would work.
Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
If Asc(e.KeyChar) = Keys.Enter Then
e.Handled = True
AxWebBrowser1.Navigate(ComboBox1.Text.ToString)
Dim bFound As Boolean
bFound = False
For i As Integer = 1 To ComboBox1.Items.Count
If ComboBox1.SelectedItem = ComboBox1.Text.ToString Then
bFound = True
Exit For
End If
Next
If bFound = False Then
ComboBox1.Items.Add(ComboBox1.Text.ToString)
End If
End If
End Sub
bceggersATcomcastDOTnet