vb 如何获得listview单元格双击事件?
vb如何获得listview单元格双击事件?如:如果点出listview第三行第一列时msgbox"超级玛丽"...
vb 如何获得listview单元格双击事件?
如:
如果点出listview第三行第一列时
msgbox "超级玛丽" 展开
如:
如果点出listview第三行第一列时
msgbox "超级玛丽" 展开
展开全部
Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Sub Form_Load()
Dim oItem As ListItem
With ListView1
.FullRowSelect = True
.LabelEdit = lvwManual
.View = lvwReport
.ColumnHeaders.Add , , "游戏名称", 100 * Screen.TwipsPerPixelX
.ColumnHeaders.Add , , "出品公司", 100 * Screen.TwipsPerPixelX
.ColumnHeaders.Add , , "存放目录", 100 * Screen.TwipsPerPixelX
Set oItem = .ListItems.Add(, , "星际争霸")
oItem.ListSubItems.Add , , "暴雪公司"
oItem.ListSubItems.Add , , "c:\starcraft\"
Set oItem = .ListItems.Add(, , "魔兽争霸")
oItem.ListSubItems.Add , , "暴雪公司"
oItem.ListSubItems.Add , , "c:\warcraft\"
Set oItem = .ListItems.Add(, , "英雄无敌")
oItem.ListSubItems.Add , , "3DO"
oItem.ListSubItems.Add , , "c:\heroes\"
Set oItem = .ListItems.Add(, , "帝国时代")
oItem.ListSubItems.Add , , "微软"
oItem.ListSubItems.Add , , "c:\aoe\"
End With
End Sub
Private Sub ListView1_DblClick()
Dim p As POINTAPI
Dim oItem As ListItem
GetCursorPos p
ScreenToClient ListView1.hwnd, p
With ListView1
Set oItem = .HitTest(p.x * Screen.TwipsPerPixelX, p.y * Screen.TwipsPerPixelY)
If Not oItem Is Nothing Then
For i = .ColumnHeaders.Count To 1 Step -1
If p.x > .ColumnHeaders(i).Left / Screen.TwipsPerPixelX Then
MsgBox "你点击了第" & oItem.Index & "个列表项的第" & i & "列"
Exit For
End If
Next
End If
End With
End Sub
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Sub Form_Load()
Dim oItem As ListItem
With ListView1
.FullRowSelect = True
.LabelEdit = lvwManual
.View = lvwReport
.ColumnHeaders.Add , , "游戏名称", 100 * Screen.TwipsPerPixelX
.ColumnHeaders.Add , , "出品公司", 100 * Screen.TwipsPerPixelX
.ColumnHeaders.Add , , "存放目录", 100 * Screen.TwipsPerPixelX
Set oItem = .ListItems.Add(, , "星际争霸")
oItem.ListSubItems.Add , , "暴雪公司"
oItem.ListSubItems.Add , , "c:\starcraft\"
Set oItem = .ListItems.Add(, , "魔兽争霸")
oItem.ListSubItems.Add , , "暴雪公司"
oItem.ListSubItems.Add , , "c:\warcraft\"
Set oItem = .ListItems.Add(, , "英雄无敌")
oItem.ListSubItems.Add , , "3DO"
oItem.ListSubItems.Add , , "c:\heroes\"
Set oItem = .ListItems.Add(, , "帝国时代")
oItem.ListSubItems.Add , , "微软"
oItem.ListSubItems.Add , , "c:\aoe\"
End With
End Sub
Private Sub ListView1_DblClick()
Dim p As POINTAPI
Dim oItem As ListItem
GetCursorPos p
ScreenToClient ListView1.hwnd, p
With ListView1
Set oItem = .HitTest(p.x * Screen.TwipsPerPixelX, p.y * Screen.TwipsPerPixelY)
If Not oItem Is Nothing Then
For i = .ColumnHeaders.Count To 1 Step -1
If p.x > .ColumnHeaders(i).Left / Screen.TwipsPerPixelX Then
MsgBox "你点击了第" & oItem.Index & "个列表项的第" & i & "列"
Exit For
End If
Next
End If
End With
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询