Library code snippets
Listview SubItem Click Detection
With this bit of code you will be able to know if a click on a listview control was made over any subitem. The example below shows the logic to that in the DblClick event of the listview control.
You Need: Listview1 ~ create some columns and set View to lvwReport.
Double click any column/row on the Listview1's grid to see the results. Note that you won't see anything unless you fill up the listview with a few items; this can be done for testing purposes in the Form_Load() event.
' In General Declarations
Private Const LVM_FIRST As Long = &H1000
Private Const LVM_HITTEST As Long = (LVM_FIRST + 18)
Private Const LVM_SUBITEMHITTEST As Long = (LVM_FIRST + 57)
Private Const LVHT_ONITEMICON As Long = &H2
Private Const LVHT_ONITEMLABEL As Long = &H4
Private Const LVHT_ONITEMSTATEICON As Long = &H8
Private Const LVHT_ONITEM As Long = (LVHT_ONITEMICON Or _
LVHT_ONITEMLABEL Or _
LVHT_ONITEMSTATEICON)
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
Dim lX as single, lY as single
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 Sub ListView1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
lX = x
lY = y
End Sub
Private Sub ListView1_DblClick()
Dim HTI As LVHITTESTINFO
With HTI
.pt.x = (lX \ Screen.TwipsPerPixelX)
.pt.y = (lY \ Screen.TwipsPerPixelY)
.flags = LVHT_ONITEM
End With
Call SendMessage(ListView1.hwnd, LVM_SUBITEMHITTEST, 0, HTI)
Dim lst As ListItem
If (HTI.iItem > -1) Then
Set lst = ListView1.ListItems(HTI.iItem + 1)
msgbox "Clicked item " & HTI.iItem + 1 & " and SubItem " & HTI.iSubItem
End If
End Sub
Related articles
Related discussion
-
Problem with migration to C# (CoCreateInstanceEx)
by LRollison (1 replies)
-
VB6 Problem Creating Shortcuts
by rb1177 (0 replies)
-
how can i open a file
by kyawswarhtun (0 replies)
-
how to save any one form what i want?
by blackguy (5 replies)
-
Build an MP3 Player
by soybees (4 replies)
Related podcasts
-
Christian Beauclair
14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...
Clicked value=
ListView1.SelectedItem.SubItems(HTI.iSubItem)
found this... it does the trick..
http://www.syncfusion.com/faq/winforms/Files/WForum_ListViewSubItem.zip
has anybody managed to get this working with vb.net?
ive been forced to use the original comctrl version of the list view since the vb.net version doesnt support subitem icons!
... so ive hacked the code into my .net app, it runs, but always returns 0,0.
Regards
DiDGE
has anybody managed to get this working with vb.net?
ive been forced to use the original comctrl version of the list view since the vb.net version doesnt support subitem icons!
... so ive hacked the code into my .net app, it runs, but always returns 0,0.
Regards
DiDGE
When I use this code in vb.net, it complains about the keyword "Any" in the declarations, so I substituted "object" but I also get an error when this line of code tries to execute: Call SendMessage(ListView1.hWnd, LVM_SUBITEMHITTEST, 0, HTI)
The error is System.ExecutionEngineException.
I had also tried creating this project in vb6 and had vb.net convert it, and I get the following warning:
'UPGRADEWARNING: Couldn't resolve default property of object HTI. Click for more: 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="vbup1037"'
Call SendMessage(ListView1.hWnd, LVMSUBITEMHITTEST, 0, HTI)
Any help would be greatly appreciated.
Prasanna
How i can get the value of the clicked cell?
If u have any sample code pls send to my account Reddy_cse@rediffmail.com
a very usefull code.........
This thread is for discussions of Listview SubItem Click Detection.