LV_GetNext() - how to find highlighdet rows?
LV_GetNext() - how to find highlighdet rows?
As I use LV_GetNext(0) to find highlighted elements then it work fine until there is focused row but not highlighted, in this sace it still return row number for them. So can I somehow to find ONLY highlighted elements independent on focus?
Re: LV_GetNext() - how to find highlighdet rows?
old basic example , how to delete marked rows
Code: Select all
;--------- script from Thalon / how to delete multiple marked rows ---
;-http://www.autohotkey.com/board/topic/4279-listview-select-column-and-start-emailurlprogram/
;--------- LISTVIEW EXAMPLE -------------------------------------------
;-- edit
; delete multiple marked rows
; add
;- example creates a subfolder _CSV with 2 text-files
;----------------------------------------------------------------------
modified=20140418
#NoEnv
#warn
SendMode Input
SetBatchLines, -1
SetWorkingDir, %A_ScriptDir%
d=`; ;- delimiter
gosub,create2Testfiles
Gui,1:Font,S13 CDefault,Lucida Console
Gui,1:Add, ListView,backgroundteal csilver grid r10 x110 y0 w480 +hscroll altsubmit gLW2 , Name|URL1
LV_ModifyCol()
Gui,1:Show,x0 y0 w600 h260,Listview_Example01 Edit=F12 DELETE=Rightclick
Gui,1:add,Listbox,x5 y10 w100 h200 Sort vLB1 gLB
Loop,%R3C%\*.csv
{
FX=%A_LoopFileName%
stringlen,L1,FX
stringmid,FA,FX,1,L1-4
GuiControl,,LB1,%FA%
}
GuiControl, ChooseString, LB1, EX1 ;- select EX1 file
;GuiControl, ChooseString, LB1, %fa% ;- select last-file
Gui,1:Font, S10 CDefault , FixedSys
Gui,1:Add,Button,gAddUrl x5 y230 w120 h20,AddUrl
;=============================================================================
LB:
Gui, 1:Default
Gui,1:Submit,nohide
LV_Delete()
LV_ModifyCol(1,220)
LV_ModifyCol(2,220)
F2=%R3C%\%LB1%.csv
loop,read,%F2%
{
BX1=
BX2=
stringsplit,BX,A_LoopReadLine,%d%,
LV_Add("",BX1,BX2)
}
return
;==============================================================
AddUrl:
if LB1=
{
msgbox,select first a genre (EX1, EX2 ....)
return
}
GuiControl,2:Focus,Name
Gui,2:Font, S10 CDefault , FixedSys
Gui,2:Add,Text, x1 y5 w80 h20, NAME
Gui,2:Add,Edit, x80 y5 w500 h20 vA21, %A21%
Gui,2:Add,Text, x1 y30 w80 h20, URL1
Gui,2:Add,Edit, x80 y30 w500 h20 vA22, %A22%
Gui,2:Add, Button, x550 y80 w40 h25, OK
Gui,2:Show, x2 y385 w600 h110, URL-INPUT
return
;---------------------------------------
2GuiClose:
2GuiEscape:
Gui,2: Destroy
return
2ButtonOK:
Gui,2:submit
if A21=
{
Gui,2: Destroy
return
}
FILEAPPEND, %A21%%d%%A22%`r`n,%F2%
Gui,2: Destroy
GoSub, LB ;update LV
return
;============================================================
LW2:
Gui, Submit,nohide
if A_GuiEvent = Normal
{
LV_GetText(C1,A_EventInfo,1)
LV_GetText(C2,A_EventInfo,2)
RN:=LV_GetNext("C")
RF:=LV_GetNext("F")
GC:=LV_GetCount()
Goto,SK12
}
;----------------------------
SK12:
if A_GuiEvent=K
{
GetKeyState,state,F12
if state=D
{
if LB1=
{
msgbox,select first a genre (EX1 or EX2....)
return
}
GuiControl,3:Focus,Name
Gui,3:Font, S10 CDefault , FixedSys
Gui,3:Add,Text, x1 y5 w80 h20, NAME
Gui,3:Add,Edit, x80 y5 w500 h20 vA31, %C1%
Gui,3:Add,Text, x1 y30 w80 h20, URL1
Gui,3:Add,Edit, x80 y30 w500 h20 vA32, %C2%
Gui,3:Add, Button, x550 y80 w40 h25, OK
Gui,3:Show, x2 y385 w600 h100, URL-INPUT
return
;---------------------------------------
3GuiClose:
3GuiEscape:
Gui, 3:Destroy
return
3ButtonOK:
Gui,3:submit
if A31=
{
Gui,3: Destroy
return
}
FileRead, FileContent, %R3C%\%LB1%.csv
FileDelete, %R3C%\%LB1%.csv
StringReplace, FileContent, FileContent, %C1%%d%%C2%, %A31%%d%%A32%
FileAppend, %FileContent%, %R3C%\%LB1%.csv
GoSub, LB
Goto,3guiclose
}
}
;============== RUN =========
if A_GuiEvent = DoubleClick
{
run,%C2%
return
}
;--------- DELETE multiple marked rows ---------------------
if A_GuiEvent = RightClick
{
C1 =
RF = 0
RFL =
Loop
{
RF:=LV_GetNext(RF)
if RF=0
break
RFL = %RF%|%RFL%
LV_GetText(C1_Temp, RF, 1)
C1 = %C1%`n%C1_Temp%
}
if C1 !=
{
MsgBox, 4, ,Want you really delete %C1% ?
IfMsgBox,No
Return
Else
{
Loop, parse, RFL, |
LV_Delete(A_LoopField)
filedelete,%F2%
Loop % LV_GetCount()
{
BX1=
BX2=
LV_GetText(BX1,A_INDEX,1)
LV_GetText(BX2,A_INDEX,2)
fileappend,%BX1%%d%%BX2%`r`n,%F2%
}
}
C1=
C2=
}
return
}
return
;------------------------
GuiClose:
ExitApp
;-------------------------------------------------------
create2Testfiles:
R3C=%A_scriptDir%\_CSV
ifnotexist,%R3C%
FileCreateDir,%R3C%
RM1=%A_scriptDir%\_CSV\EX1.csv
ifnotexist,%RM1%
{
fileappend,Archive_Math%d%http://archives.math.utk.edu/popmath.html`r`n,%RM1%
fileappend,Archive_org%d%http://www.archive.org`r`n,%RM1%
fileappend,Archive_Video%d%https://www.youtube.com/channel/UCGp4u0WHLsK8OAxnvwiTyhA`r`n,%RM1%
fileappend,Humour_Dilbert%d%http://dilbert.com`r`n,%RM1%
fileappend,Youtube_Sunset%d%https://www.youtube.com/watch?v=YfQh199PALY`r`n,%RM1%
}
RM2=%A_scriptDir%\_CSV\EX2.csv
ifnotexist,%RM2%
{
fileappend,Autohotkey%d%http://ahkscript.org/boards/index.php`r`n,%RM2%
fileappend,Puzzle games%d%http://www.chiark.greenend.org.uk/~sgtatham/puzzles/`r`n,%RM2%
}
return
;=================== end script ============================================
;--------- script from Thalon / how to delete multiple marked rows ---
;-http://www.autohotkey.com/board/topic/4279-listview-select-column-and-start-emailurlprogram/
;--------- LISTVIEW EXAMPLE -------------------------------------------
;-- edit
; delete multiple marked rows
; add
;- example creates a subfolder _CSV with 2 text-files
;----------------------------------------------------------------------
modified=20140418
#NoEnv
#warn
SendMode Input
SetBatchLines, -1
SetWorkingDir, %A_ScriptDir%
d=`; ;- delimiter
gosub,create2Testfiles
Gui,1:Font,S13 CDefault,Lucida Console
Gui,1:Add, ListView,backgroundteal csilver grid r10 x110 y0 w480 +hscroll altsubmit gLW2 , Name|URL1
LV_ModifyCol()
Gui,1:Show,x0 y0 w600 h260,Listview_Example01 Edit=F12 DELETE=Rightclick
Gui,1:add,Listbox,x5 y10 w100 h200 Sort vLB1 gLB
Loop,%R3C%\*.csv
{
FX=%A_LoopFileName%
stringlen,L1,FX
stringmid,FA,FX,1,L1-4
GuiControl,,LB1,%FA%
}
GuiControl, ChooseString, LB1, EX1 ;- select EX1 file
;GuiControl, ChooseString, LB1, %fa% ;- select last-file
Gui,1:Font, S10 CDefault , FixedSys
Gui,1:Add,Button,gAddUrl x5 y230 w120 h20,AddUrl
;=============================================================================
LB:
Gui, 1:Default
Gui,1:Submit,nohide
LV_Delete()
LV_ModifyCol(1,220)
LV_ModifyCol(2,220)
F2=%R3C%\%LB1%.csv
loop,read,%F2%
{
BX1=
BX2=
stringsplit,BX,A_LoopReadLine,%d%,
LV_Add("",BX1,BX2)
}
return
;==============================================================
AddUrl:
if LB1=
{
msgbox,select first a genre (EX1, EX2 ....)
return
}
GuiControl,2:Focus,Name
Gui,2:Font, S10 CDefault , FixedSys
Gui,2:Add,Text, x1 y5 w80 h20, NAME
Gui,2:Add,Edit, x80 y5 w500 h20 vA21, %A21%
Gui,2:Add,Text, x1 y30 w80 h20, URL1
Gui,2:Add,Edit, x80 y30 w500 h20 vA22, %A22%
Gui,2:Add, Button, x550 y80 w40 h25, OK
Gui,2:Show, x2 y385 w600 h110, URL-INPUT
return
;---------------------------------------
2GuiClose:
2GuiEscape:
Gui,2: Destroy
return
2ButtonOK:
Gui,2:submit
if A21=
{
Gui,2: Destroy
return
}
FILEAPPEND, %A21%%d%%A22%`r`n,%F2%
Gui,2: Destroy
GoSub, LB ;update LV
return
;============================================================
LW2:
Gui, Submit,nohide
if A_GuiEvent = Normal
{
LV_GetText(C1,A_EventInfo,1)
LV_GetText(C2,A_EventInfo,2)
RN:=LV_GetNext("C")
RF:=LV_GetNext("F")
GC:=LV_GetCount()
Goto,SK12
}
;----------------------------
SK12:
if A_GuiEvent=K
{
GetKeyState,state,F12
if state=D
{
if LB1=
{
msgbox,select first a genre (EX1 or EX2....)
return
}
GuiControl,3:Focus,Name
Gui,3:Font, S10 CDefault , FixedSys
Gui,3:Add,Text, x1 y5 w80 h20, NAME
Gui,3:Add,Edit, x80 y5 w500 h20 vA31, %C1%
Gui,3:Add,Text, x1 y30 w80 h20, URL1
Gui,3:Add,Edit, x80 y30 w500 h20 vA32, %C2%
Gui,3:Add, Button, x550 y80 w40 h25, OK
Gui,3:Show, x2 y385 w600 h100, URL-INPUT
return
;---------------------------------------
3GuiClose:
3GuiEscape:
Gui, 3:Destroy
return
3ButtonOK:
Gui,3:submit
if A31=
{
Gui,3: Destroy
return
}
FileRead, FileContent, %R3C%\%LB1%.csv
FileDelete, %R3C%\%LB1%.csv
StringReplace, FileContent, FileContent, %C1%%d%%C2%, %A31%%d%%A32%
FileAppend, %FileContent%, %R3C%\%LB1%.csv
GoSub, LB
Goto,3guiclose
}
}
;============== RUN =========
if A_GuiEvent = DoubleClick
{
run,%C2%
return
}
;--------- DELETE multiple marked rows ---------------------
if A_GuiEvent = RightClick
{
C1 =
RF = 0
RFL =
Loop
{
RF:=LV_GetNext(RF)
if RF=0
break
RFL = %RF%|%RFL%
LV_GetText(C1_Temp, RF, 1)
C1 = %C1%`n%C1_Temp%
}
if C1 !=
{
MsgBox, 4, ,Want you really delete %C1% ?
IfMsgBox,No
Return
Else
{
Loop, parse, RFL, |
LV_Delete(A_LoopField)
filedelete,%F2%
Loop % LV_GetCount()
{
BX1=
BX2=
LV_GetText(BX1,A_INDEX,1)
LV_GetText(BX2,A_INDEX,2)
fileappend,%BX1%%d%%BX2%`r`n,%F2%
}
}
C1=
C2=
}
return
}
return
;------------------------
GuiClose:
ExitApp
;-------------------------------------------------------
create2Testfiles:
R3C=%A_scriptDir%\_CSV
ifnotexist,%R3C%
FileCreateDir,%R3C%
RM1=%A_scriptDir%\_CSV\EX1.csv
ifnotexist,%RM1%
{
fileappend,Archive_Math%d%http://archives.math.utk.edu/popmath.html`r`n,%RM1%
fileappend,Archive_org%d%http://www.archive.org`r`n,%RM1%
fileappend,Archive_Video%d%https://www.youtube.com/channel/UCGp4u0WHLsK8OAxnvwiTyhA`r`n,%RM1%
fileappend,Humour_Dilbert%d%http://dilbert.com`r`n,%RM1%
fileappend,Youtube_Sunset%d%https://www.youtube.com/watch?v=YfQh199PALY`r`n,%RM1%
}
RM2=%A_scriptDir%\_CSV\EX2.csv
ifnotexist,%RM2%
{
fileappend,Autohotkey%d%http://ahkscript.org/boards/index.php`r`n,%RM2%
fileappend,Puzzle games%d%http://www.chiark.greenend.org.uk/~sgtatham/puzzles/`r`n,%RM2%
}
return
;=================== end script ============================================
Re: LV_GetNext() - how to find highlighdet rows?
For me, LV_GetNext(0) returns 0 if the ListView contains only one focused but not selected row. If additional selected rows exist, it returns the number of the first selected row.