用这个函数: x,y是鼠标当前位置,可以从 mouseDown 事件得到;返回真值就会选择当前行,假值则表示没办法选定(比如点在空白处)Function selectItem(ByRef objLv As ListView, ByVal X As Single, Y As Single) As Boolean '选定MOUSE DOWN位置的ITEM
On Error GoTo aErr Dim objItem As ListItem
Set objItem = objLv.HitTest(X, Y) objLv.ListItems(objItem.Index).Selected = True
selectItem = True
Exit Function
aErr: selectItem = False
End Function
在窗体定义两个公用变量,保存鼠标坐标 dim xPos as single dim yPos as single'在listview的mousemove事件中,将当前鼠标坐标赋值给变量 xPos=x yPos-y'在listview的mouseup事件中,用hittest方法测试点击位置,并判断 if listview.hittest(xpos,ypos) is nothing then exit sub '忽略 else popupmenu 菜单 end if
x,y是鼠标当前位置,可以从 mouseDown 事件得到;返回真值就会选择当前行,假值则表示没办法选定(比如点在空白处)Function selectItem(ByRef objLv As ListView, ByVal X As Single, Y As Single) As Boolean
'选定MOUSE DOWN位置的ITEM
On Error GoTo aErr Dim objItem As ListItem
Set objItem = objLv.HitTest(X, Y)
objLv.ListItems(objItem.Index).Selected = True
selectItem = True
Exit Function
aErr:
selectItem = False
End Function
dim xPos as single
dim yPos as single'在listview的mousemove事件中,将当前鼠标坐标赋值给变量
xPos=x
yPos-y'在listview的mouseup事件中,用hittest方法测试点击位置,并判断
if listview.hittest(xpos,ypos) is nothing then
exit sub '忽略
else
popupmenu 菜单
end if