Fast Search CoboBox and ListBox using Windows API
Using windows API SendMessage Call, this class Searches for a matching string in ListBox (In Association with a textbox) or ComboBox. And believe me its really Fast, Super Fast... ;-)
AI
Yapay Zeka Özeti: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Kaynak Kod
Option Explicit
Public Sub FindIndexStr(ctlSource As Control, _
ByVal str As String, intKey As Integer, _
Optional ctlTarget As Variant)
Dim lngIdx As Long
Dim FindString As String
If (intKey < 32 Or intKey > 127) And _
(Not (intKey = 13 Or intKey = 8)) Then Exit Sub
If Not intKey = 13 Or intKey = 8 Then
If Len(ctlSource.Text) = 0 Then
FindString = str & Chr$(intKey)
Else
FindString = Left$(str, ctlSource.SelStart) & Chr$(intKey)
End If
End If
If intKey = 8 Then
If Len(ctlSource.Text) = 0 Then Exit Sub
Dim numChars As Integer
numChars = ctlSource.SelStart - 1
'FindString = Left(str, numChars)
If numChars > 0 Then FindString = Left(str, numChars)
End If
If IsMissing(ctlTarget) And TypeName(ctlSource) = "ComboBox" Then
Set ctlTarget = ctlSource
If intKey = 13 Then
Call SendMessageStr(ctlTarget.hWnd, _
CB_SHOWDROPDOWN, True, 0&)
Exit Sub
End If
lngIdx = SendMessageStr(ctlTarget.hWnd, _
CB_FINDSTRING, -1, FindString)
ElseIf TypeName(ctlTarget) = "ListBox" Then
If intKey = 13 Then Exit Sub '???
lngIdx = SendMessageStr(ctlTarget.hWnd, _
LB_FINDSTRING, -1, FindString)
Else
Exit Sub
End If
If lngIdx <> -1 Then
ctlTarget.ListIndex = lngIdx
If TypeName(ctlSource) = "TextBox" Then ctlSource.Text = ctlTarget.List(lngIdx)
ctlSource.SelStart = Len(FindString)
ctlSource.SelLength = Len(ctlSource.Text) - ctlSource.SelStart
End If
intKey = 0
End Sub
Orijinal Yorumlar (3)
Wayback Machine'den kurtarıldı