Making an item selected in a Combo Box

To make an item selected in a Combo box you have 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 combo box 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 CB_SELECTSTRING = &H14D

'**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(Combo1.hwnd, CB_SELECTSTRING, -1, ByVal GivenStr)

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