VBNotebook Home | Functions | Click-Free Combo ListIndex - This routine sets the ListIndex property of a combo box without generating a Click event. If you set the ListIndex property of a combo box you will generate a click event. In early versions of VB, this was considered a bug, but it became a feature after a number of programmers started using this property to generate click events. Unfortunately, if you don't want to generate a click event you either have to resort to using module level flag variables or use the routine below.
First, in General|Declarations, include the following...
__________________________________________________________________________________________
Private Const CB_SETCURSEL = &H14E
Private Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As String) As Long
__________________________________________________________________________________________
And the routine itself....
__________________________________________________________________________________________
Sub SetComboListIndex(cboCombo As ComboBox, ByVal iIndex As Integer)
Dim nRet As Long
nRet = SendMessageByString(cboCombo.hwnd, CB_SETCURSEL, iIndex, "")
End Sub
__________________________________________________________________________________________
Copyright 2000-2005, J. Frank Carr