我不認爲自動完成的來源是你想要這個。
相反,我建議你在DropDown模式下使用組合框。
ComboBox3.DropDownStyle = ComboBoxStyle.DropDown
你需要做出的排行榜部分可見,當控件獲得聚焦...
Private Sub ComboBox3_GotFocus(sender As Object, e As EventArgs) Handles ComboBox3.GotFocus
ComboBox3.DroppedDown = True
End Sub
然後根據每當文本框的變化重建列表內容。
Private Sub ComboBox3_KeyUp(sender As Object, e As EventArgs) Handles ComboBox3.KeyUp
Dim Ss = ComboBox3.SelectionStart
Dim Sl = ComboBox3.SelectionLength
.... rebuilt the list items here ...
Dim Ss = ComboBox3.SelectionStart
Dim Sl = ComboBox3.SelectionLength
ComboBox3.DroppedDown = True
End Sub
完整的例子
Public Class Form4
Dim employees() As String = New String() {"Hamilton, David", _
"Hensien, Kari", "Hammond, Maria", "Harris, Keith", _
"Henshaw, Jeff D.", "Hanson, Mark", "Harnpadoungsataya, Sariya", _
"Harrington, Mark", "Harris, Keith", "Hartwig, Doris", _
"Harui, Roger", "Hassall, Mark", "Hasselberg, Jonas", _
"Harnpadoungsataya, Sariya", "Henshaw, Jeff D.", "Henshaw, Jeff D.", _
"Hensien, Kari", "Harris, Keith", "Henshaw, Jeff D.", _
"Hensien, Kari", "Hasselberg, Jonas", "Harrington, Mark", _
"Hedlund, Magnus", "Hay, Jeff", "Heidepriem, Brandon D."}
Private Sub ComboBox3_GotFocus(sender As Object, e As EventArgs) Handles ComboBox3.GotFocus
ComboBox3.DroppedDown = True
End Sub
Private Sub ComboBox3_KeyUp(sender As Object, e As KeyEventArgs) Handles ComboBox3.KeyUp
Dim Ss = ComboBox3.SelectionStart ' + 1
ComboBox3.Items.Clear()
Dim SearchText As String = UCase(ComboBox3.Text)
For Each Str As String In employees
Dim UStr As String = UCase(Str)
If InStr(UStr, SearchText) = 1 OrElse InStr(UStr, " " & SearchText) > 0 Then
ComboBox3.Items.Add(Str)
End If
Next
ComboBox3.SelectionStart = Ss
ComboBox3.SelectionLength = 0
ComboBox3.DroppedDown = True
End Sub
End Class
確保您設置comboboxstyle到下拉
你必須找到一個現有的,包括到您的項目,或建立自己的。默認自動完成行爲僅從開始檢查 –
我試圖找到一個,但到目前爲止沒有運氣 –