在窗体上设置一个名称为Combo1的下拉组合框,一个名称为Label1的标签。要求当在组合框中输入一个新项后按回车键时,
1个回答

Private Sub Combo1_KeyPress(KeyAscii As Integer)

Dim bExist As Boolean

If KeyAscii = 13 Then

For i = 0 To Combo1.ListCount

If Combo1.Text = Combo1.List(i) Then

Label1.Caption = "输入项已存在组合框中"

bExist = True

Exit For

End If

Next i

If bExist = False Then

Combo1.AddItem Combo1.Text

Label1.Caption = "已添加输入项"

End If

End If

End Su