I have this function to return the control's ListIndex based on the given 'text'.
I use it like so:
My question is how can I return the List Index given the ItemData instead of the text
Code:
Public Function returnIndex(ByVal objListCtrl As Control, ByVal strItemText As String) As Integer
Dim lngVal As Long, lngListCtrl As Long
lngVal = -1
If TypeOf objListCtrl Is ComboBox Then
lngListCtrl = CB_FINDSTR
Else
lngListCtrl = LB_FINDSTR
End If
'if list is empty, exit function return a False value
If objListCtrl.ListCount < 1 Then Exit Function
lngVal = SendMessageString(objListCtrl.hwnd, CB_FINDSTR, -1&, strItemText)
returnIndex = lngVal
Set objListCtrl = Nothing
End Function
Code:
cboCategory.Listindex = returnIndex(cboCategory, "Fish")