Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21089

return List Index

$
0
0
I have this function to return the control's ListIndex based on the given '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

I use it like so:

Code:

cboCategory.Listindex = returnIndex(cboCategory, "Fish")
My question is how can I return the List Index given the ItemData instead of the text

Viewing all articles
Browse latest Browse all 21089

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>