Help with ListView & LV_Add

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

Help with ListView & LV_Add

17 Jul 2018, 05:20

1. i would like to allow choose from the list only 1 item,
possible replace the checkboxwith radio ? or either to get some msgbox when more than 1 item selected ?

2. when clicking on "Show Slected Item" its omits c:\ from the msgbox,
i'd like to get the full path name.

thanks in advance!

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.


; General Profile size
vDir1 = c:
vList := ""
excludedFolders := ""

Loop, Files, % vDir1 "\*", D ; folders
{
	if A_LoopFileName in %foldersBlacklist%
	{
		excludedFolders .= """" . A_LoopFileFullPath . """ "
		continue
	}
	
	vList .= A_LoopFileFullPath . "|"
}


vList := SubStr(vList, 1, -1)
ListProfile := % StrReplace(vList, "`n", "|")


Gui, Default

Gui -MinimizeBox -MaximizeBox
Gui, Add, ListView, x10 y10 h250 w250 Checked, %vDir1%
For each, file in % StrSplit(RTrim(ListProfile, "|"), "|")
    LV_Add(,substr(file,4))
Gui, Add, Button, gButoon1_Profile, Show Selected Item
Gui, Add, Button, gButoon3_Profile, Exit
Gui, Show, ,
return

Butoon1_Profile:
Gui,Submit, noHide

 names_Profile := ""

 Row_Profile := 0
 Loop {
   Row_Profile := LV_GetNext(Row_Profile, "C")  ; Return next Row_C "checked"
   	                            ; next LV_GetNext will start from this position
   	                            
   If (!Row_Profile)                    ; No more chekeds
      Break                     ; Break Loop
      
   LV_GetText(name, Row_Profile, 1)
   names_Profile .=  chr(34) RegExReplace(name,"^.*\\") chr(34) " "

   MsgBox, %names_Profile%
 }
 
if names_Profile = 
	MsgBox, nothing selected

return
  
Butoon3_Profile:
ExitApp

GuiEscape:
GuiClose:
ExitApp
User avatar
jmeneses
Posts: 524
Joined: 28 Oct 2014, 11:09
Location: Catalan Republic

Re: Help with ListView & LV_Add

17 Jul 2018, 06:56

Code: Select all


   If (!Row_Profile) {          ; No more chekeds
   	  If (A_index>2)
   	      Msgbox 0x40000,, % "More than one!!" 
      Break                     ; Break Loop
   }  
   LV_GetText(name, Row_Profile, 1)
   names_Profile .=   chr(34) RegExReplace(name,"^.*\\") chr(34) " "
   names_Profile_2 .=  vDir1 "\" name "`n"
   MsgBox, %names_Profile%
 }
   MsgBox, % names_Profile_2
Donec Perficiam
User avatar
Tomer
Posts: 366
Joined: 21 Aug 2016, 05:11

Re: Help with ListView & LV_Add

18 Jul 2018, 01:58

tnx jmeneses!

1)
i made some changes to make it work properly,
if theres a better method please post it.

2)
possible to sort the list by date modified (from new to old) ?

tnx in advance!

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.


; General Profile size
vDir1 = c:
vList := ""
excludedFolders := ""

Loop, Files, % vDir1 "\*", D ; folders
{
	if A_LoopFileName in %foldersBlacklist%
	{
		excludedFolders .= """" . A_LoopFileFullPath . """ "
		continue
	}
	
	vList .= A_LoopFileFullPath . "|"
}


vList := SubStr(vList, 1, -1)
ListProfile := % StrReplace(vList, "`n", "|")


Gui, Default

Gui -MinimizeBox -MaximizeBox
Gui, Add, ListView, x10 y10 h250 w250 Checked, %vDir1%
For each, file in % StrSplit(RTrim(ListProfile, "|"), "|")
    LV_Add(,substr(file,4))
Gui, Add, Button, gButoon1_Profile, Show Selected Item
Gui, Add, Button, gButoon3_Profile, Exit
Gui, Show, ,
return

Butoon1_Profile:
Gui,Submit, noHide

 names_Profile_2 := ""

 Row_Profile := 0
 Loop {
   Row_Profile := LV_GetNext(Row_Profile, "C")  ; Return next Row_C "checked"
   	                            ; next LV_GetNext will start from this position
   	                            

   If (!Row_Profile) {          ; No more chekeds
   	  If (A_index>2)
     {  
		  vaule = 0
   	      Msgbox 0x40000,, % "More than one!!"
     }
	       Break                     ; Break Loop
   }
   vaule = 1
   LV_GetText(name, Row_Profile, 1)
   names_Profile_2 .=  vDir1 "\" name "`n"
 }

if names_Profile_2 =
{
	vaule = 0
	MsgBox, nothing selected
}

   if vaule = 1
          MsgBox % names_Profile_2
 
return
  
Butoon3_Profile:
ExitApp

GuiEscape:
GuiClose:
ExitApp
User avatar
Tomer
Posts: 366
Joined: 21 Aug 2016, 05:11

Re: Help with ListView & LV_Add

19 Jul 2018, 08:07

any help would be appreciated
garry
Posts: 3764
Joined: 22 Dec 2013, 12:50

Re: Help with ListView & LV_Add

20 Jul 2018, 11:22

2)
possible to sort the list by date modified (from new to old) ?

Code: Select all

#NoEnv
#Warn
SendMode Input
SetWorkingDir %A_ScriptDir% 

vDir1 = C:
vList := ""
excludedFolders := ""
foldersBlacklist=Windows

Gui,2:default
Gui,2: Add , ListView, x20 y70 r40 w810  backgroundgray grid vLV1 gLV1a checked altsubmit Multi, NR|FolderName in %vdir1% sorted by TimeModified|Fullpath|TimeModified
LV_ModifyCol(1,90)
LV_ModifyCol(2,400)
LV_ModifyCol(3,0)
LV_ModifyCol(4,100)
LV_ModifyCol(1,"integer")
LV_ModifyCol(4,"digit")
LV_ModifyCol(4, "right") 


Gui,2: Add, Button, gShowChecked, Show Checked Items
Gui,2: Add, Button, gExit1, Exit
Gui,2: Show, ,
gosub,fill
return
exit1:
2Guiclose:
exitapp

ShowChecked:
Gui,2:submit,nohide
Gui,2:ListView, LV1
GS:=LV_GetCount()
delim:="    "
eec:=""
rnm=0
  loop,%gs%
  {
  RNM := LV_GetNext(RNM,"checked")
  if not rnm
      break
  LV_GetText(C1,rnm,1)    ;- number
  LV_GetText(C2,rnm,2)    ;- name
  LV_GetText(C3,rnm,3)    ;- fullpath
  LV_GetText(C4,rnm,4)    ;- TimeModified
  eec .= "Row=" . rnm  delim c1 delim c2  delim  c3 delim c4 . "`r`n"
  }
if eec<>  
msgbox, 262208, ,eec=`n%eec%
return
;---------------

Fill:
Gui,2: Submit, Nohide
Gui,2:ListView, LV1

ib=0
LV_Delete()
Loop, Files, % vDir1 "\*", D                        ;- folders
{
	if A_LoopFileName in %foldersBlacklist%
	{
		excludedFolders .= """" . A_LoopFileFullPath . """ "
		continue
	}
   ib++	
   SplitPath,A_LoopFileFullPath, name, dir, ext, name_no_ext, drive
   LV_Add("",ib,name,A_LoopFileFullPath,a_loopfiletimemodified)

}
LV_ModifyCol(4, "Logical SortDesc") 
return
;----------------

LV1a:
Gui,2: Submit, Nohide
Gui,2:ListView, LV1
RC:=LV_GetNext("C")
RF:=LV_GetNext("F")
GC:=LV_GetCount()
  If A_GuiEvent=Doubleclick
     {
     LV_GetText(C1,A_EventInfo,1)
     LV_GetText(C2,A_EventInfo,2)
     LV_GetText(C3,A_EventInfo,3)
     LV_GetText(C4,A_EventInfo,4)
	 msgbox,%c1%`n%c2%`n%c3%`n%c4%`n----------`nExcluded=`n%excludedFolders%
     return
     }
return
;======================================================
User avatar
Tomer
Posts: 366
Joined: 21 Aug 2016, 05:11

Re: Help with ListView & LV_Add

23 Jul 2018, 02:32

thanks alot garry!

looks tough,
will definitely check it out!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, doodles333, jameswrightesq and 289 guests