AHMKC1
asked on
click cell in listview
How I find the mouse click position (or Cell value) in a listview in vb 6
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This code will give u the exact subitem clicked
http://vbnet.mvps.org/index.html?code/comctl/lvhittest.htm
http://vbnet.mvps.org/index.html?code/comctl/lvhittest.htm
hey DanRollins,
think my second answer (the second answer posted also) is the best one,
it does exactly what the Author asks
//
thank you for your continuing work of cleaning those rather old questions!
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
Const LVM_FIRST = &H1000&
Const LVM_HITTEST = LVM_FIRST + 18
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Type LVHITTESTINFO
pt As POINTAPI
flags As Long
iItem As Long
iSubItem As Long
End Type
Private Sub Form_Load()
With ListView1.ListItems
.Add Text:="Test item #1"
.Add Text:="Test item #2"
.Add Text:="Long long long test item #3"
End With
End Sub
Private Sub ListView1_MouseMove(Button
Dim lvhti As LVHITTESTINFO
Dim lItemIndex As Long
Static m_lCurItemIndex As Long
lvhti.pt.X = X / Screen.TwipsPerPixelX
lvhti.pt.Y = Y / Screen.TwipsPerPixelY
lItemIndex = SendMessage(ListView1.hwnd
If m_lCurItemIndex <> lItemIndex Then
m_lCurItemIndex = lItemIndex
If m_lCurItemIndex <> 0 Then
Me.Caption = ListView1.ListItems(m_lCur
End If
End If
End Sub