restrict event

User avatar
sal21
PlatinumLounger
Posts: 4266
Joined: 26 Apr 2010, 17:36

restrict event

Post by sal21 »

Private Sub ListView1_DblClick()

dim RM as long

RM = Empty
RM = Me.ListView1.SelectedItem.Index

End sub

i need to restrict this event only if i double clichk on a cell of column 1 of listview

User avatar
SpeakEasy
4StarLounger
Posts: 449
Joined: 27 Jun 2021, 10:46

Re: restrict event

Post by SpeakEasy »

You need to check the X position of the mouse cursor when the click occurs, if it is less than the first column's width then you have clicked in the first column, so exit the dblclick event

User avatar
sal21
PlatinumLounger
Posts: 4266
Joined: 26 Apr 2010, 17:36

Re: restrict event

Post by sal21 »

SpeakEasy wrote: ↑
03 Apr 2023, 23:08
You need to check the X position of the mouse cursor when the click occurs, if it is less than the first column's width then you have clicked in the first column, so exit the dblclick event
Infact! Googling docet...
Tell me to use hittest, but never used.
Example?
Tks for siggestion.

User avatar
SpeakEasy
4StarLounger
Posts: 449
Joined: 27 Jun 2021, 10:46

Re: restrict event

Post by SpeakEasy »

I don't think hittest gains you anything

Try something like

Code: Select all

Option Explicit
Private myX As Single

Private Sub Form_Load()
' Initialise listview with some data
Dim wombat As ListItem
Set wombat = ListView1.ListItems.Add(, , "Example")
wombat.ListSubItems.Add , , "some dummy data"
wombat.ListSubItems.Add , , "some more dummy data"
Set wombat = ListView1.ListItems.Add(, , "Example2")
wombat.ListSubItems.Add , , "some dummy data"
wombat.ListSubItems.Add , , "some more dummy data"
Set wombat = ListView1.ListItems.Add(, , "Example3")
wombat.ListSubItems.Add , , "some dummy data"
wombat.ListSubItems.Add , , "some more dummy data"
End Sub

Private Sub ListView1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    myX = x
End Sub

Private Sub ListView1_DblClick()

If myX <= ListView1.ListItems(1).Left + ListView1.ListItems(1).Width Then
    Debug.Print "Column 0"
    Exit Sub
End If
    
Debug.Print "Not column 0"

End Sub

User avatar
sal21
PlatinumLounger
Posts: 4266
Joined: 26 Apr 2010, 17:36

Re: restrict event

Post by sal21 »

SpeakEasy wrote: ↑
04 Apr 2023, 11:38
I don't think hittest gains you anything

Try something like

Code: Select all

Option Explicit
Private myX As Single

Private Sub Form_Load()
' Initialise listview with some data
Dim wombat As ListItem
Set wombat = ListView1.ListItems.Add(, , "Example")
wombat.ListSubItems.Add , , "some dummy data"
wombat.ListSubItems.Add , , "some more dummy data"
Set wombat = ListView1.ListItems.Add(, , "Example2")
wombat.ListSubItems.Add , , "some dummy data"
wombat.ListSubItems.Add , , "some more dummy data"
Set wombat = ListView1.ListItems.Add(, , "Example3")
wombat.ListSubItems.Add , , "some dummy data"
wombat.ListSubItems.Add , , "some more dummy data"
End Sub

Private Sub ListView1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    myX = x
End Sub

Private Sub ListView1_DblClick()

If myX <= ListView1.ListItems(1).Left + ListView1.ListItems(1).Width Then
    Debug.Print "Column 0"
    Exit Sub
End If
    
Debug.Print "Not column 0"

End Sub
TKS, I can test toomorrow.

User avatar
SpeakEasy
4StarLounger
Posts: 449
Joined: 27 Jun 2021, 10:46

Re: restrict event

Post by SpeakEasy »

And?