它基本上做的是檢查用戶輸入是否已經在ComboBox1中。如果是,提醒用戶。如果沒有,它將它添加到組合框中這個Visual Basic代碼爲什麼工作?
我沒有得到的是「For Each StringIterador In ComboBox1.Items loop」。 Item對象如何放置在String變量中?我知道字符串是對象,但是...您不能只將一個隨機對象放入一個字符串變量中,可以嗎?也字符串稍後用作Item對象後面「ComboBox1.GetItemText(StringIterador)」
Private Sub ComboBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles ComboBox1.KeyPress
Dim StringIterador As String
If e.KeyChar = ControlChars.Cr Then
If ComboBox1.Text <> "" Then
For Each StringIterador In ComboBox1.Items
If ComboBox1.GetItemText(StringIterador).Equals(ComboBox1.Text) Then
MsgBox("ya está en la lista")
Exit Sub
Else
ComboBox1.Items.Add(ComboBox1.Text)
Exit Sub
End If
Next
End If
End If
End Sub
將'Option Strict On'放置在文件的開頭或整個項目設置中 – Fabio
@Fabio:這是一個值得+1的評論 – christutty