

Public Sub AutoCompleteKeyUp(ByVal Combo As ComboBox, ByVal e As KeyEventArgs)
Dim strTyped As String
Dim intFoundIndex As Integer
Dim objFoundItem As Object
Dim strFoundText As String
Dim strAppendText As String
' Ignore basic selection keys
Select Case e.KeyCode
Case Keys.Back, Keys.Left, Keys.Right, Keys.Up, _
Keys.Delete, Keys.Down, Keys.CapsLock
Return
End Select
' Find what user has typed in list
strTyped = Combo.Text
intFoundIndex = Combo.FindString(strTyped)
' If found...
If intFoundIndex >= 0 Then
' Get list item (actual type depends on whether data bound)
objFoundItem = Combo.Items(intFoundIndex)
' Use control to resolve text - in case data bound
strFoundText = Combo.GetItemText(objFoundItem)
' Append the typed text to rest of the found string
' (text is set twice due to a combo box quirk:
' on certain platforms, setting just once ignores casing!)
strAppendText = strFoundText.Substring(strTyped.Length)
Combo.Text = strTyped & strAppendText
Combo.Text = strTyped & strAppendText
' Select the appended text
Combo.SelectionStart = strTyped.Length
Combo.SelectionLength = strAppendText.Length
End If
End Sub
Public Sub AutoCompleteLeave(ByVal Combo As ComboBox)
' Correct casing when leaving combo
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 ComboBox1.KeyUp
AutoCompleteKeyUp(ComboBox1, e)
End Sub
'
Private Sub ComboBox1_Leave(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles ComboBox1.Leave
AutoCompleteLeave(ComboBox1)
End Sub
cualquier sugerencia
