北京 | 上海 | 天津 | 重庆 | 广州 | 深圳 | 珠海 | 汕头 | 佛山 | 中山 | 东莞 | 南京 | 苏州 | 无锡 | 常州 | 南通 | 扬州 | 徐州 | 杭州 | 温州 | 宁波 | 台州 | 福州 | 厦门 | 泉州 | 龙岩 | 合肥 | 芜湖 | 成都 | 遂宁 | 长沙 | 株洲 | 湘潭 | 武汉 | 南昌 | 济南 | 青岛 | 烟台 | 潍坊 | 淄博 | 济宁 | 太原 | 郑州 | 石家庄 | 保定 | 唐山 | 西安 | 大连 | 沈阳 | 长春 | 昆明 | 兰州 | 哈尔滨 | 佳木斯 | 南宁 | 桂林 | 海口 | 贵阳 | 西宁 | 乌鲁木齐 | 包头 |
Option Compare Database
'原这句代码为为:(但提示为红色错误)
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_KeyUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs)
Handles ComboBox1.KeyUp = AutoCompleteKeyUp(ComboBox1, e)
End Sub
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
'忽略这些基本操作键
Select Case e.KeyCode
Case Keys.Back, Keys.Left, Keys.Right, Keys.Up, _
Keys.Delete, Keys.Down, Keys.CapsLock
Return
End Select
'看看用户输入了些什么
strTyped = Combo.Text
intFoundIndex = Combo.FindString(strTyped)
'如果找到了的话……
If intFoundIndex >= 0 Then
'获取Combo下的匹配项
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