| Set ListIndex Property Without Generating Click Event With a list box or a combo box, if you set the listindex property, you will also generate a click event for the control. This code allows you to set the listindex property (i.e., highlight a particular list item) without generating a click event. Option Explicit Private Declare Function SendMessage Lib "user32" Alias _ "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, _ ByVal wParam As Long, lParam As Any) As Long Private Const LB_SETCURSEL = &H186 Private Const CB_SETCURSEL = &H14E Public Function SetListCtlIndex(lstCtl As Object, _ ByVal lngIndex As Long) As Boolean '************************************************ 'SETS Listindex of a list box or combo box without generating a click event on the control 'PARAMETERS: lstCtl = list or combo box ' lngIndex = List Index to set it to 'RETURNS: True if successful, false otherwise 'EXAMPLE: SetListCtlIndex list1, 2 '************************************************ Dim lRet As Long If TypeOf lstCtl Is ListBox Then lRet = SendMessage(lstCtl.hWnd, LB_SETCURSEL, lngIndex, 0&) SetListCtlIndex = (lRet = lngIndex) SetListCtlIndex = (lRet = lngIndex) ElseIf TypeOf lstCtl Is ComboBox Then lRet = SendMessage(lstCtl.hWnd, CB_SETCURSEL, lngIndex, 0&) SetListCtlIndex = (lRet = lngIndex) End If End Function |
Set ListIndex Property Without Generating Click Ev |
Express News India | Freelance ecommerce web development India