vb combobox 事件
就像 百度的 输入框一样
我现在已经能根据关键字 找到相关内容 加入到列表中 可惜不知道怎么让他动态的显示 我是在 vb中 用控件combobox
Private Sub Combo1_Change()
Dim Count As Integer
Dim KeyCount As Integer
Dim tmpArray() As String
Dim SQL As String
Combo1.Refresh
'清空上次的下拉列表数据
While Combo1.ListCount <> 0
Combo1.RemoveItem (0)
Wend
'当输入框没有数据的时候,不做检索
If Trim(Combo1.Text) = "" Then
GoTo Gendsub
End If
'获取DB连接
Call ModDB.getDBCon(Con)
'模糊查询以输入框开头的数据集
SQL = "select ID from userInfo where ID like'" & Trim(Combo1.Text) & "%'"
'执行SQL
Call ModDB.getRecord(Rs, Con, SQL, flg)
'连接错误
If flg = 1 Then
GoTo Gendsub
End If
'其他错误
If flg >= 2 Then
Con.Close
GoTo Gendsub
End If
'DB检索件数
Count = Rs.RecordCount
'检索的字段数
KeyCount = 1
'取得检索结果
Call ModDB.setDataByKey(Rs, Count, KeyCount, tmpArray())
'将检索结果加入到下拉列表中
For i = 0 To Count - 1
Combo1.AddItem tmpArray(i, 0), i
Next i
SendKeys "{F4}"
Con.Close
Gendsub:
End Sub 展开
动态显示对吗?比如ABC的字符你输入类似的A就能出现吗?如果是这样的话就给你个代码:<添加一个combo和list控件!>
Private Sub Combo1_Change()
Dim sString As String
Dim start As Integer
start = Combo1.SelStart
sString = Left(Combo1.Text, start)
For i = 0 To Combo1.ListCount - 1 Step 1
Dim sitem As String
sitem = Combo1.List(i)
sitem = Left(sitem, start)
If sitem = sString Then
List1.ListIndex = i
List1.Visible = True
Exit For
End If
Next
End Sub
Private Sub Combo1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Combo1.ListIndex = List1.ListIndex
List1.Visible = False
End If
End Sub
Private Sub Form_Load()
Combo1.AddItem "abc"
Combo1.AddItem "acb"
Combo1.AddItem "edf"
Combo1.AddItem "ffff"
'向Combo1添加列表项
Dim i As Integer
For i = 0 To Combo1.ListCount - 1 Step 1
List1.AddItem Combo1.List(i), i
Next
List1.Visible = False
'向List1添加与Combo1相同的列表项
End Sub
具体是这样的摆放位置!看图图
SendKeys "{RIGHT}"