Making an item selected in the List box

To make an item selected in the list box you need to set the listindex property to the item's index in the list. To find out the index of an item you need not to loop thru all the items in the listbox by comparing the string value, rather you can do it very fast using SendMessage API.

'**Include the following lines in the declaration part

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Long, lParam As Any) As Long

Const LB_SELECTSTRING = &H18C

'**Include the following code in any of the event from where you want to call SendMessage
Dim lReturnVal as long
Dim GivenStr as String

'Set the string value in the item to be selected
GivenStr = "Test String"
lReturnVal = SendMessage(List1.hwnd, LB_SELECTSTRING, -1, ByVal GivenStr)

In the above statement, if the function is successful 'lReturnVal' will return the listindex of the string found.