Private Sub AutoCompleteKeyUp(ByVal Combo As ComboBox, ByVal e As
Dim strTyped As String
Dim intFoundIndex As Integer
Dim objFoundItem As Object
Dim strFoundText As String
Dim strAppendText As String
' 忽略特殊键
Select Case
Case
Return
End Select
' 在查询列表中找到
strTyped = Combo.Text
intFoundIndex = Combo.FindString(strTyped)
If intFoundIndex >= 0 Then
objFoundItem = Combo.Items(intFoundIndex)
strFoundText = Combo.GetItemText(objFoundItem)
strAppendText = strFoundText.Substring(strTyped.Length)
Combo.Text = strTyped & strAppendText
Combo.SelectionStart = strTyped.Length
Combo.SelectionLength = strAppendText.Length
End If
End Sub
Private Sub AutoCompleteLeave(ByVal Combo As
Dim intFoundIndex As Integer
intFoundIndex = Combo.FindStringExact(Combo.Text)
Combo.SelectedIndex = -1
Combo.SelectedIndex = intFoundIndex
End Sub
Private Sub ComboBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles
AutoCompleteKeyUp(ComboBox1, e)
End Sub
Private Sub ComboBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles
AutoCompleteLeave(ComboBox1)
End Sub
|