VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)
首页 - 经验之谈 - 改变Combo的ListIndex而不发生 Click 事件
发表评论(0)作者:, 平台:, 阅读:18690, 日期:2000-03-12
改变 ListIndex而不发生 Click 事件

在修改 Combo 或 Listview 的ListIndex 时, 会发生 Click 事件, 下面的

函数可以阻止该事件。

声明:

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

Const CB_GETCURSEL = &H147

Const CB_SETCURSEL = &H14E

Const LB_SETCURSEL = &H186

Const LB_GETCURSEL = &H188

函数:

Public Function SetListIndex(lst As Control, ByVal NewIndex As Long) As

Long

 

If TypeOf lst Is ListBox Then

Call SendMessage(lst.hWnd, LB_SETCURSEL, NewIndex, 0&)

SetListIndex = SendMessage(lst.hWnd, LB_GETCURSEL, NewIndex, 0&)

ElseIf TypeOf lst Is ComboBox Then

Call SendMessage(lst.hWnd, CB_SETCURSEL, NewIndex, 0&)

SetListIndex = SendMessage(lst.hWnd, CB_GETCURSEL, NewIndex, 0&)

End If

End Function