VBcoders Browse New Submit Contact Sign In

No account? Register free

Forgot password?

Fast Search CoboBox and ListBox using Windows API

Pankaj Nagar  (1 Submission)   Windows API Call/Explanation   Visual Basic 3.0   Advanced   Wed 3rd February 2021

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... ;-)

Inputs
ctlSource: The Source control (ComboBox or TextBox in case to search in ListBox) str: The string to search (i.e. .Text) intKey : Keycode of Key pressed (i.e. KeyAscii Parameter in KeyPress Event) Optional ctlTarget : If to search in ListBox The ListBox Control

Assumes
Usage: ' 1 - In the module declaration declare Dim cBS As New clsBoxSearch ' 2 - Write on TextBox or ComboBox Keypress event Private Sub cmbSearch_KeyPress(KeyAscii As Integer) cBS.FindIndexStr cmbSearch, cmbSearch.Text, KeyAscii End Sub Private Sub txtSearchItem_KeyPress(KeyAscii As Integer) cBS.FindIndexStr txtSearchItem, txtSearchItem.Text, KeyAscii, lstSearchName End Sub

Returns
None: Just sets the ListIndex to the Found String

API Declarations
'**********************************************************************
'Declaration for Search Routines in ListBox (LB) and ComboBox (CB)
Public Const LB_FINDSTRING As Long = &H18F
Public Const LB_FINDSTRINGEXACT As Long = &H1A2
Public Const CB_ERR As Long = (-1)
Public Const LB_ERR As Long = (-1)
Public Const WM_USER As Long = &H400
Public Const CB_FINDSTRING As Long = &H14C
Public Const CB_SHOWDROPDOWN As Long = &H14F
Public Declare Function SendMessageStr Lib _
"user32" Alias "SendMessageA" _
(ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As String) As Long
'***********************************************************************

Rate Fast Search CoboBox and ListBox using Windows API (4(4 Vote))
Fast Search CoboBox and ListBox using Windows API.bas

Fast Search CoboBox and ListBox using Windows API Comments

No comments yet — be the first to post one!

Post a Comment

0/1000 characters