Incremental Key Seasrch, ComboBox

G

Guest

I am trying to duplicate this functionality from VB6:

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 CB_FINDSTRING = &H14C

Private Sub cboSunday_KeyPress(KeyAscii As Integer)
Call ComboIncrementalSearch(cboSunday, KeyAscii)
End Sub

Public Sub ComboIncrementalSearch(cbo As ComboBox, KeyAscii As Integer)
Static dTimerLast As Double
Static sSearch As String
Static hWndLast As Long
Dim nRet As Long
Const MAX_KEYPRESS_TIME = 0.5

If (KeyAscii < 32 Or KeyAscii > 127) Then Exit Sub
If (Timer - dTimerLast) < MAX_KEYPRESS_TIME And hWndLast = cbo.hWnd Then
sSearch = sSearch & Chr$(KeyAscii)
Else
sSearch = Chr$(KeyAscii)
hWndLast = cbo.hWnd
End If
nRet = SendMessage(cbo.hWnd, CB_FINDSTRING, -1, ByVal sSearch)
If nRet >= 0 Then
cbo.ListIndex = nRet
End If
KeyAscii = 0
dTimerLast = Timer
End Sub

so that essentially as you type in keys in a combobox, it brings you
automatically to the closest matching item. Anyone have any example code for
that?

Thanks in advance.

Ed
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top