devxlogo

Finding a String in a Combo Box

Finding a String in a Combo Box

The CBFindString()procedure searches for a string in a combo box byusing the SendMessage() API function to find a specific entry in the list.This is much more efficient than searching using VB code:

 Declare Function SendMessage Lib "User" _ (ByVal hWnd As Integer, ByVal wMsg As Integer, _ ByVal wParam As Integer, lParam As Any) As Long Sub CBFindString (ctlEdit As Control, _ sSearch As String) Dim lPos As Long Const CB_FINDSTRING = &H40C lPos = SendMessage(ctlEdit.hWnd, CB_FINDSTRING, _ 0, ByVal sSearch) If lPos >= 0 Then ctlEdit.ListIndex = lPos End If End Sub 

devx-admin

Share the Post: