' *************Declarations
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) _
As Long
Private Const WM_SETREDRAW As Long = &HB&
Private Const CB_FINDSTRING As Long = &H14C&
' *************Here is the sub that will implement auto search
Public Sub SearchCombo(InControl As Object)
On Error GoTo trap
Dim StrPos As Long
Dim lPos As Long
Dim SearchStr As String
If TypeOf InControl Is ComboBox Then
StrPos = InControl.SelStart
SearchStr = Left$(InControl.Text, StrPos)
If lPos >= 0 Then
InControl.Text = InControl.List(lPos)
InControl.ListIndex = lPos
End If
With InControl
.SelStart = StrPos
.SelLength = Len(InControl.Text)
End With
End If
Exit Sub
trap:
MsgBox Err.Description
End Sub
'**************Implement it like this************
Private Sub Combo1_Change()
Call SearchCombo(Combo1) '<--pass the combo box to the sub by name
End Sub
Private Sub Form_Load()
Combo1.AddItem "asdasd"
Combo1.AddItem "fsdasd"
Combo1.AddItem "bsdasd"
Combo1.AddItem "ssdasd"
Combo1.AddItem "rsdasd"
End Sub
1.设一个单词长度字段。
2 设COMBOBOX SORT为TRUE
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Sub Combo1_Change()
Dim iStart As Integer
Dim sString As String
Static iLeftOff As Integer
iStart = 1
iStart = Combo1.SelStart
If iLeftOff <> 0 Then Combo1.SelStart = iLeftOff: iStart = iLeftOff
End Sub
Private Sub Form_Load()
Dim i As Long
For i = 1 To 500
Randomize
Combo1.AddItem Chr(Int(Rnd * 26) + 97) & Chr(Int(Rnd * 26) + 97) & Chr(Int(Rnd * 26) + 97) & Chr(Int(Rnd * 26) + 97) & Chr(Int(Rnd * 26) + 97)
Next
Combo1.Text = ""
End Sub