Avoiding Bound Controls
ItemIndex - a brief description...
This function uses an API call to return the index of the requested string in the ListBox if it exists. If the item does not exist -1 (one) is returned. The API Message communicates with the ListBox or ComboBox as a basic windows control and is the fastest way to do this.
Function ItemIndex (lstX As Control, ByVal sSelect As String) As Long
Dim lPos As Long
' Search for the exact string in the ListBox or Combo
' and return the list index of that item
If TypeOf lstX Is ComboBox Then
lPos = BIND_SendMessageString(lstX.hWnd, BIND_CB_FINDSTRINGEXACT, -1, sSelect)
Else
lPos = BIND_SendMessageString(lstX.hWnd, BIND_LB_FINDSTRINGEXACT, -1, sSelect)
End If
' Return the index of the item if found, or 0 if we didn't
ItemIndex = lPos
End Function
![]()