Page 1 of 1

Retrieve folder contents, then put them into a DDL.

Posted: 09 Aug 2022, 11:25
by Ben the Coder
Hi,
Is there a way to retrieve files from a folder (say A_WinDir\Fonts), then put the contents of the folder into a DropDownList?
Thanks!

Re: Retrieve folder contents, then put them into a DDL.

Posted: 09 Aug 2022, 12:23
by Xtra
Example:

Code: Select all

Loop, Files, % A_WinDir . "\Fonts\*.*"
    fileList .= A_LoopFileName . "|"

Gui, Add, DropDownList, gSelectedFile vFileChoice, % RTrim(fileList, "|")
Gui, Show
return

SelectedFile:
    Gui, Submit, NoHide
    MsgBox, 4096, you selected, % FileChoice
return

Re: Retrieve folder contents, then put them into a DDL.

Posted: 09 Aug 2022, 20:05
by Ben the Coder
It works! :)
Incorporating it into my AHK script...

Re: Retrieve folder contents, then put them into a DDL.

Posted: 09 Aug 2022, 20:22
by flyingDman
I think that a DDL is somewhat of a dud when you have many items to list. It's not searchable so you have to scroll. A small listview is much more versatile and can be implemented together with a search box with just a few more lines of code:

Code: Select all

gui, add, text,x8, search:
gui, add, edit, x+10 y3 w105 gsearch vneedle
gui, add, listview, x8 y+2 w150 r5 vMyLV gpick -hdr,Files
gui, show
search:
gui, submit, nohide
lV_delete()
loop, files, % a_windir "\Fonts\*.*"
	if (instr(A_LoopFileName, needle))
		lv_add("", A_LoopFileName)
LV_ModifyCol(1,130)
return

pick:
lv_GetText(item, A_EventInfo,1)
msgbox % item
return

Re: Retrieve folder contents, then put them into a DDL.

Posted: 10 Aug 2022, 09:36
by Ben the Coder
Ok.
I'll try your suggestion now.

Re: Retrieve folder contents, then put them into a DDL.

Posted: 11 Aug 2022, 01:30
by iPhilip
flyingDman wrote:
09 Aug 2022, 20:22
I think that a DDL is somewhat of a dud when you have many items to list. It's not searchable so you have to scroll.
You might want to check out @teadrinker's searchable ComboBox (post).

Re: Retrieve folder contents, then put them into a DDL.

Posted: 11 Aug 2022, 11:37
by flyingDman
@iPhilip Thanks. That's very clever but it does not match the versatility of the listview. After a small change in my script above, clicking on an item return the full path.

Code: Select all

gui, add, text,x8, search:
gui, add, edit, x+10 y3 w105 gsearch vneedle
gui, add, listview, x8 y+2 w150 r5 vMyLV gpick -hdr,Files|Path
gui, show
LV_ModifyCol(2,0)
search:
gui, submit, nohide
lV_delete()
loop, files, % a_windir "\Fonts\*.*"
	if (instr(A_LoopFileName, needle))
		lv_add("", A_LoopFileName,A_LoopFileFullPath)
LV_ModifyCol(1,130)
return

pick:
lv_GetText(item, A_EventInfo,2)
msgbox % item
return