Help to detect any change in row selection for listview Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
labrint
Posts: 379
Joined: 14 Jun 2017, 05:06
Location: Malta

Help to detect any change in row selection for listview

Post by labrint » 05 Dec 2021, 08:11

Ok so I have used GUIEvent to detect double clicks, but row selection may change using cursor keys etc.

I simply want to detect any changes in LV row selection however way that happens.

I saw @flyingDman's code

Code: Select all

Gui, Add, ListView, Checked AltSubmit gtrigger, Rows
lv_add("","Row1")
lv_add("","Row2")
lv_add("","Row3")
gui, show,, gui
return

trigger:
if (A_GuiEvent = "I" and errorlevel = "c")
		msgbox % A_EventInfo
return
to detect rows based on checking / unchecking a row as well. I wish not to have to click a checkbox.

User avatar
labrint
Posts: 379
Joined: 14 Jun 2017, 05:06
Location: Malta

Re: Help to detect any change in row selection for listview

Post by labrint » 05 Dec 2021, 08:27

labrint wrote:
05 Dec 2021, 08:11
Ok so I have used GUIEvent to detect double clicks, but row selection may change using cursor keys etc.

I simply want to detect any changes in LV row selection however way that happens.

I saw @flyingDman's code

Code: Select all

Gui, Add, ListView, Checked AltSubmit gtrigger, Rows
lv_add("","Row1")
lv_add("","Row2")
lv_add("","Row3")
gui, show,, gui
return

trigger:
if (A_GuiEvent = "I" and errorlevel = "c")
		msgbox % A_EventInfo
return
to detect rows based on checking / unchecking a row as well. I wish not to have to click a checkbox.
I havetried the following statement

Code: Select all

If (guiEvent = "DoubleClick") OR (guiEvent = "Normal") OR (guiEvent = "I")
but there was an issue with the I event grabbing the deselected row instead of the selected when I go up or down with the cursor.

Tried this as per documentation but didn't work.

Code: Select all

If (guiEvent = "DoubleClick") OR (guiEvent = "Normal") OR (guiEvent = "I") and InStr(ErrorLevel, "S", true))

User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: Help to detect any change in row selection for listview

Post by mikeyww » 05 Dec 2021, 08:34

Code: Select all

Gui, Add, ListView, Checked AltSubmit gTrigger, Rows
LV_Add("", "Row1")
LV_Add("", "Row2")
LV_Add("", "Row3")
Gui, Show,, ListView
Return

Trigger:
Critical
If (A_GuiEvent != "I")
 Return
SoundBeep, 2000
StringCaseSense, On
msg =
Loop, Parse, ErrorLevel
{ msg .= msg ? " + " : ""
  Switch A_LoopField {
   Case "S": msg .= "Selected"
   Case "s": msg .= "Deselected"
   Case "F": msg .= "Focused"
   Case "f": msg .= "Defocused"
   Case "C": msg .= "Checked"
   Case "c": msg .= "Unchecked"
 }
}
MouseGetPos, x, y
ToolTip, % tip := "Row " A_EventInfo ": " msg (tip ? "`n" tip : ""), x + 130, y
Return

User avatar
labrint
Posts: 379
Joined: 14 Jun 2017, 05:06
Location: Malta

Re: Help to detect any change in row selection for listview

Post by labrint » 05 Dec 2021, 09:20

mikeyww wrote:
05 Dec 2021, 08:34

Code: Select all

Gui, Add, ListView, Checked AltSubmit gTrigger, Rows
LV_Add("", "Row1")
LV_Add("", "Row2")
LV_Add("", "Row3")
Gui, Show,, ListView
Return

Trigger:
Critical
If (A_GuiEvent != "I")
 Return
SoundBeep, 2000
StringCaseSense, On
msg =
Loop, Parse, ErrorLevel
{ msg .= msg ? " + " : ""
  Switch A_LoopField {
   Case "S": msg .= "Selected"
   Case "s": msg .= "Deselected"
   Case "F": msg .= "Focused"
   Case "f": msg .= "Defocused"
   Case "C": msg .= "Checked"
   Case "c": msg .= "Unchecked"
 }
 
 It works but I want to trigger only when Selected + Focused (hence the row its currently on)
}
MouseGetPos, x, y
ToolTip, % tip := "Row " A_EventInfo ": " msg (tip ? "`n" tip : ""), x + 130, y
Return

User avatar
labrint
Posts: 379
Joined: 14 Jun 2017, 05:06
Location: Malta

Re: Help to detect any change in row selection for listview

Post by labrint » 05 Dec 2021, 09:21

labrint wrote:
05 Dec 2021, 09:20
mikeyww wrote:
05 Dec 2021, 08:34

Code: Select all

Gui, Add, ListView, Checked AltSubmit gTrigger, Rows
LV_Add("", "Row1")
LV_Add("", "Row2")
LV_Add("", "Row3")
Gui, Show,, ListView
Return

Trigger:
Critical
If (A_GuiEvent != "I")
 Return
SoundBeep, 2000
StringCaseSense, On
msg =
Loop, Parse, ErrorLevel
{ msg .= msg ? " + " : ""
  Switch A_LoopField {
   Case "S": msg .= "Selected"
   Case "s": msg .= "Deselected"
   Case "F": msg .= "Focused"
   Case "f": msg .= "Defocused"
   Case "C": msg .= "Checked"
   Case "c": msg .= "Unchecked"
 }
 

}
MouseGetPos, x, y
ToolTip, % tip := "Row " A_EventInfo ": " msg (tip ? "`n" tip : ""), x + 130, y
Return
It works but I want to trigger only when Selected + Focused (hence the row its currently on)

User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: Help to detect any change in row selection for listview  Topic is solved

Post by mikeyww » 05 Dec 2021, 09:24

Code: Select all

Gui, Add, ListView, Checked AltSubmit gTrigger, Rows
LV_Add("", "Row1")
LV_Add("", "Row2")
LV_Add("", "Row3")
Gui, Show,, ListView
Return

Trigger:
Critical
err := ErrorLevel, msg := ""
If (A_GuiEvent != "I")
 Return
StringCaseSense, On
Loop, Parse, err
{ msg .= msg ? " + " : ""
  Switch A_LoopField {
   Case "S": msg .= "Selected"
   Case "s": msg .= "Deselected"
   Case "F": msg .= "Focused"
   Case "f": msg .= "Defocused"
   Case "C": msg .= "Checked"
   Case "c": msg .= "Unchecked"
  }
}
MouseGetPos, x
ToolTip, % tip := "Row " A_EventInfo ": " msg (tip ? "`n" tip : ""), x + 300
If Instr(err, "S") && Instr(err, "F")
 MsgBox, 64, Ouch!, Triggered row %A_EventInfo%!, 1
Return

garry
Posts: 3740
Joined: 22 Dec 2013, 12:50

Re: Help to detect any change in row selection for listview

Post by garry » 05 Dec 2021, 10:41

@mikeyww . thank you, here an example : run checked rows / or also run with doubleclick

Code: Select all

#Warn
setworkingdir,%a_scriptdir%
filename1=Run checked TestFiles
tmrx=%a_scriptdir%\MyTestFiles    ;- here are 3 xy.ahk files for test
ifnotexist,%tmrx%
  {
  filecreatedir,%tmrx%
  fileappend,run`,charmap,%tmrx%\charmap-test.ahk
  fileappend,runwait`,%comspec% /c ping www.autohotkey.com -n 4,%tmrx%\ping-test.ahk
  fileappend,runwait`,%comspec% /k systeminfo,%tmrx%\systeminfo-test.ahk
  }
extx=ahk
Gui,2:default
Gui,2:Color,Black, Black
Gui,2:Font,  S14  ,Lucida Console
Gui,2:Add,ListView,backgroundBlack cYellow x0 y0 w650 h450 +hscroll altsubmit vA1 gGLV checked, I|Name|FullPath
LV_ModifyCol(1,60),LV_ModifyCol(2,250),LV_ModifyCol(3,0),LV_ModifyCol(1,"integer")
Gui,2:add,button, x10  y470 w180 h27 gSelect_all  ,Select_all
Gui,2:add,button, x200 y470 w180 h27 gDeselect_all,Deselect_all
Gui,2:add,button, x450 y470 w120 h27 gStart1,START
Gui,2: Show      , x0  y0   w700 h520,%filename1%
gosub,fillx
return
;-----------------------------------------------------
2Guiclose:
exitapp
;-----------------------------------------------------
Select_All:
LV_Modify(0, "Check")     ; Select all.
return
;-----------------------------------------------------
Deselect_All:
LV_Modify(0, "-check")    ; De-select all.
return
;-----------------------------------------------------
GLV:
Gui,2:ListView, A1
LV_GetText(C1,A_EventInfo,1),  LV_GetText(C2,A_EventInfo,2),  LV_GetText(C3,A_EventInfo,3)
if (A_GuiEvent = "DoubleClick")
 {
 aa:="ROW= " . a_eventinfo . "`nC1=" . c1 . "`nC2=" . c2 . "`nC3=" . c3 
 msgbox,%aa%
 try
   run,%c3%
 }
return
;-------------------------------------
Start1:
LV_Modify(0,"-select")
e:=""
Rowx    :=0
Checkedx:=i:=0
while i:=LV_GetNext(i, "Checked")
  Checkedx++                                     ;- total checked
;-- run checked :
While (Rowx := LV_GetNext(Rowx, "checked"))
{
   C3=   
   LV_GetText(C3,Rowx,3)
   e .= C3 . "`n"
   gosub,runx
   C3=
   LV_Modify(rowx, "-check")

}
msgbox, 262208, ,ENDED`n%e%,
e=
Return
;-----------------------------------
Runx:
   try
     runwait,%c3%
return
;---------- Fill-Listview ----------
fillx:
Gui,2:submit,nohide
Gui,2:ListView,A1
I=0
LV_Delete()
Loop, %tmrx%\*.*, 0, 1
 {
 If A_LoopFileExt in %Extx%
   {
   I++
   O=%A_LoopFileName%
   T=%A_LoopFileFullPath%
     LV_Add("Check" 0, I, O, T)
  }
 }
LV_ModifyCol(2, "Sort")
LV_Modify(LV_GetCount(), "Vis")     ;scrolls down
return
;--------------------------------------------------
;=============================================================

User avatar
labrint
Posts: 379
Joined: 14 Jun 2017, 05:06
Location: Malta

Re: Help to detect any change in row selection for listview

Post by labrint » 06 Dec 2021, 02:56

Hey @mikeyww is there a way to replace switch? Due to the fact it doesn't work on all AHK versions?

PS I fixed it by commenting out the switch section, works just the same as the condition uses the letter only.

User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: Help to detect any change in row selection for listview

Post by mikeyww » 06 Dec 2021, 04:49

Yes, Switch is equivalent to "If... then... Else If ... then...".

Post Reply

Return to “Ask for Help (v1)”