get the selected items names from ListView Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Tomer
Posts: 366
Joined: 21 Aug 2016, 05:11

get the selected items names from ListView

24 May 2018, 03:39

i want to get the name\s of the selected items from the ListView,
ex: if i checked line2 & line4 then by clickin on "Show selected items" i'll get it this way:
"line2" "line4"

thanks in advance

Code: Select all

List := "line1|line2|line3|line4|line5"

Gui Add, ListView, Checked -Hdr, FileFullPath
For each, file in % StrSplit(RTrim(List, "|"), "|")
    LV_Add(, file)
Gui, Add, Button, gButoon1, Show selected items
Gui Show
return

Butoon1:
LV_GetText(file,())
MsgBox % file ; not working :(
User avatar
jmeneses
Posts: 524
Joined: 28 Oct 2014, 11:09
Location: Catalan Republic

Re: get the selected items names from ListView  Topic is solved

24 May 2018, 04:35

Hello Tomer, try this

Code: Select all

#NoEnv 
#SingleInstance force 
#Persistent   

List := "line1|line2|line3|line4|line5"

Gui Add, ListView, Checked -Hdr, FileFullPath
For each, file in % StrSplit(RTrim(List, "|"), "|")
    LV_Add(, file)
Gui, Add, Button, gButoon1, Show selected items
Gui, Add, Button, gButoon2, Return object selected items

Gui Show
return

Butoon1:
 names := ""
 Row := 0    
 Loop {
   Row := LV_GetNext(Row, "C")  ; Return next row "checked"
   	                            ; next LV_GetNext will start from this position
   	                            
   If (!Row)                    ; No more chekeds
      Break                     ; Break Loop
      
   LV_GetText(name, Row, 1)      
   names .= name " "
 }
  Msgbox % names
 Return

Butoon2(){
 Row := 0
 names := Object()
 Loop {
   Row := LV_GetNext(Row, "C")
   If (!Row) 
      Break
   LV_GetText(name, Row, 1)
   names.Insert(name)  	
 }
 For i, name in names
   Msgbox % name
 } 
Donec Perficiam
User avatar
Tomer
Posts: 366
Joined: 21 Aug 2016, 05:11

Re: get the selected items names from ListView

27 May 2018, 08:00

any chance to omit the "c:\" from % names ?

Code: Select all

#NoEnv 
#SingleInstance force 
#Persistent   

List := "c:\line1|c:\line2|c:\line3|c:\line4|c:\line5"

Gui Add, ListView, Checked -Hdr, FileFullPath
For each, file in % StrSplit(RTrim(List, "|"), "|")
    LV_Add(, file)
Gui, Add, Button, gButoon1, Show selected items
Gui, Add, Button, gButoon2, Return object selected items

Gui Show
return

Butoon1:
 names := ""
 Row := 0    
 Loop {
   Row := LV_GetNext(Row, "C")  ; Return next row "checked"
   	                            ; next LV_GetNext will start from this position
   	                            
   If (!Row)                    ; No more chekeds
      Break                     ; Break Loop
      
   LV_GetText(name, Row, 1)      
   names .= name " "
 }
  Msgbox % names
 Return

Butoon2(){
 Row := 0
 names := Object()
 Loop {
   Row := LV_GetNext(Row, "C")
   If (!Row) 
      Break
   LV_GetText(name, Row, 1)
   names.Insert(name)  	
 }
 For i, name in names
   Msgbox % name
 } 
User avatar
jmeneses
Posts: 524
Joined: 28 Oct 2014, 11:09
Location: Catalan Republic

Re: get the selected items names from ListView

27 May 2018, 10:19

Tomer wrote:any chance to omit the "c:\" from % names ?
I'm sorry but I do not understand your goal

Code: Select all

For each, file in % StrSplit(RTrim(List, "|"), "|")
    LV_Add(,substr(file,4))
Donec Perficiam
User avatar
Tomer
Posts: 366
Joined: 21 Aug 2016, 05:11

Re: get the selected items names from ListView

28 May 2018, 05:30

jmeneses wrote:
Tomer wrote:any chance to omit the "c:\" from % names ?
I'm sorry but I do not understand your goal

Code: Select all

For each, file in % StrSplit(RTrim(List, "|"), "|")
    LV_Add(,substr(file,4))
Thanks,
thats what I needed,
but i need the text which % names returns will be inside quotes (each item inside quotes)
ex: if i check from list these items: c:\line2 & c:\line4 ,
then % names will return exactly: "line2" "line4"

thanks for your help so far :)
User avatar
jmeneses
Posts: 524
Joined: 28 Oct 2014, 11:09
Location: Catalan Republic

Re: get the selected items names from ListView

28 May 2018, 06:42

Code: Select all


Butoon1:
 names := ""
 Row := 0    
 Loop {
   Row := LV_GetNext(Row, "C")  ; Return next row "checked"
   	                            ; next LV_GetNext will start from this position
   	                            
   If (!Row)                    ; No more chekeds
      Break                     ; Break Loop
      
   LV_GetText(name, Row, 1)      
   names .=  chr(34) RegExReplace(name,"^.*\\") chr(34) " "
 }
  Msgbox % names
 Return

Donec Perficiam
User avatar
Tomer
Posts: 366
Joined: 21 Aug 2016, 05:11

Re: get the selected items names from ListView

28 May 2018, 10:44

wonderful!
ty jmeneses!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: AHK_user and 221 guests